Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with contact form

    I am working on getting a contact form up and running for a website and have taken an example of someone else's. Only problem is I don't know anything about php so getting the form to work is proving difficult.

    I have highlighted the lines I am unsure of with orange.
    I don't know what I am supposed to put instead of junk@junk.om
    Also, I am unsure how to change the URL to my contactthanks.html page. Everything I have tried will not work.

    PHP Code:
    <?php

    // CHANGE THE VARIABLES BELOW

    [COLOR="DarkOrange"]$EmailFrom "junk@junk.com";[/COLOR]
    $EmailTo "aharper2000@hotmail.com";
    $Subject "Contact Form Submission";

    $Name Trim(stripslashes($_POST['Name'])); 
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $Message Trim(stripslashes($_POST['Message'])); 

    // prepare email body text
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

    // redirect to success page
    // CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
    if ($success){
      [
    COLOR="DarkOrange"]print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";[/COLOR]
    }
    else{
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>
    Any help would be appreciated.
    Here is a link to what I've got working so far: http://ah.mjtippet.com/contact.html

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    For the first one, put whatever email you want it to arrive from.
    For the second, use a header instead of a meta:
    PHP Code:
    if ($success)
    {
        
    header('Location: http://yoursite.com/yourthankspage.html');
        exit();
    }
    else
    {
        
    header('Location: http://yoursite.com/yourerrorpage.html');
        exit();


  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help. Are you able to tell me why you've changed it from print to header?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It isn't about the print, it is about what was printed. Originally it would print out some HTML which was a Meta refresh. This would rely on the browser understanding it (most browsers do but it is obsolete). Using the header it ensures that it will always work no matter what browser.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •