Contact Form

Discussion in 'PHP' started by eight84, Jun 21, 2010.

  1. #1
    I used this code on my last website. i am now coding my site by myself and learning as I go. Could someone point out what I'm missing here? This is my HTML for the form

    <form method="post" action="send_mail.php" method="post">
    <p></p>
    <p>
    <input name="name" type="text" id="name" value="" size="75"  />
    <p>
    <input name="email" type="text" id="email" value="" size="75"  />
    <p>
    
    <textarea name="details" rows="8" cols="65">Details about project and anything else you think I need to know!</textarea>
     <p><button type="submit">send</button>
    	</p>
      </form> 
    Code (markup):


    Now I guess this should be a contact.php page right? So it could "echo" back "mail sent successfully. Here's my send_mail.php page:

    <?php
    // Prep The message
    $eol = "\r\n";
    $message = $eol;
    $message .= "Name: ". $_POST['name'] .$eol;
    $message .= "E-Mail: ". $_POST['email'] .$eol;
    $message .= "Details: ". $_POST['details'] .$eol;
    
    // Send
    if(mail('michele@eight84.com', 'Eight84 Website E-Mail', $message))
    {
    	$response = "E-Mail Successfully Sent";
    }
    else
    {
    	$response = "E-Mail Failed to Send";
    }
    
    // Redirect
    header("Location: index.php?response=". $response);
    exit();
    ?>
    Code (markup):
    I tried changing "header("Location: index.php?response=". $response);"

    to: header("Location: contact.php?response=". $response);


    but it isn't sending the "response" message just appears to refresh the page although it DOES send the email.
     
    eight84, Jun 21, 2010 IP
  2. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Is the response still in the URL? also what browser are you using?
     
    Cozmic, Jun 21, 2010 IP
  3. eight84

    eight84 Active Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    ive tried it on IE 8, firefox, and safari....am I missing something in the HTML? Whats the respond in the URL?
     
    eight84, Jun 21, 2010 IP
  4. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #4
    ?response=something

    is that in the url when you are redirected?
     
    Cozmic, Jun 21, 2010 IP
  5. eight84

    eight84 Active Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    eight84, Jun 21, 2010 IP
  6. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #6
    if($response == 'E-Mail Successfully Sent') { Echo 'E-Mail Successfully Sent'; } 
    PHP:
    or you could just handle all responses
    if($_REQUEST['response']) { echo $_REQUEST['response']; } 
    PHP:
    i would recommend filtering your response variable though, ya know xss and other injections :) better safe than sorry even though it'll only effect them.
    add that to the page you are sending to (index.php)
     
    ttyler333, Jun 21, 2010 IP
  7. eight84

    eight84 Active Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    Where do I add that exactly? I don't know coding very well
     
    eight84, Jun 21, 2010 IP
  8. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #8
    your mail script has this code "header("Location: index.php?response=". $response);" right? or does it say "header("Location: contact.php?response=". $response);"

    if it is the contact.php one then i'd add it to contact.php. :)
     
    ttyler333, Jun 21, 2010 IP
  9. eight84

    eight84 Active Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #9
    ahh yeah that's what was missing!! thanks for your help!! :)
     
    eight84, Jun 21, 2010 IP
  10. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #10
    Anything to get my posts closer to 25 :) and i can help along the way. your welcome
     
    ttyler333, Jun 21, 2010 IP