Results 1 to 6 of 6

Thread: PHP Contact Form Does Not Capture Email and Name

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default PHP Contact Form Does Not Capture Email and Name

    Hi,

    Sorry for my noobness in PHP. I am still figuring out how to fix this small simple PHP contact form fix. Hope that you can teach me please.

    When the form is filled up, I can't know the sender's name and email address. Hence, when I hit the reply, I don't know what is the sender's email and his name.

    Many thanks in advance.

    HTML Code
    HTML Code:
    	<table width="89%" border="0" cellpadding="0" cellspacing="0">
    	<tr>
    	      <td height="58" valign="top"><img src="image/contact/feed_form.png" width="109" height="42"></td>
    	</tr>
    	<tr>
    	
    	<td height="254" valign="top">
    	<form name="form1" method="post" action="mail.php" onSubmit="return isValidEmail(this)">
    	<table height="78%">
    	<tr>
            <td width="310" height="40" align="left" valign="top">
            <input type="text" name="name" style="width: 290px; height: 30px; padding: 2px; border: 1px solid #c0c0c0;" placeholder="Your name" >
            </td>
        </tr>
    	<tr>
    		          <td height="39" valign="top" align="left"> <input name="email" type="text" style="width: 290px; height: 30px; padding: 2px; border: 1px solid #c0c0c0;" placeholder="Your email" /></td>
    	</tr>
    	<tr>
    	              <td height="110" valign="top"><textarea name="message" style="width: 290px; height: 100px; padding: 2px; border: 1px solid #c0c0c0;"></textarea></td>
    	</tr>
    	<tr>
    	<td height="52" align="right" valign="top"><input type="submit" style="width: 100px; height: 50px;" value="Send"/></td>
    	</tr>
    			
    
    </table>
    PHP Code
    PHP Code:
    <?php header("Refresh: 3;url=contact.html"); ?>
    <?php $to 
    "xxx@gmail.com"$name $_REQUEST['name']; $subject "Feedback from customer ".$name."!"
    $email $_REQUEST['mail'] ; 
    $message $_REQUEST['message'] ; $headers "From: $email"$sent mail($to$subject$message$headers) ; 
    if(
    $sent) {print "Your mail was sent successfully. <br/>You will be redirected to the contact us page in 3 seconds"; } else {print "We encountered an error sending your mail"; } ?>

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Nothing in your code is sending an email. Maybe there's more code that you didn't paste in?
    - Josh

  3. The Following User Says Thank You to JShor For This Useful Post:

    fcuk89 (08-17-2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    (sorry, i just think i might be able to say this?)

    I believe you need to put the code in mail().


    Sorry if I'm wrong. I just want to try and help others .

  5. The Following User Says Thank You to Techykid3 For This Useful Post:

    fcuk89 (08-17-2011)

  6. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by fcuk89 View Post
    PHP Code:
    <?php 
    $to 
    "xxx@gmail.com"$name $_REQUEST['name']; $subject "Feedback from customer ".$name."!"
    $email $_REQUEST['mail'] ; 
    $message $_REQUEST['message'] ; 
    $headers "From: $email"
    $sent mail($to$subject$message$headers) ; // <-- right there
    if($sent) {
       print 
    "Your mail was sent successfully. <br/>You will be redirected to the contact us page in 3 seconds"
    } else {
       print 
    "We encountered an error sending your mail"

    ?>
    He is using mail(), guys.

    You're not sending successfully because you're looking for 'mail' when the name of the field in the form was 'email'. Use $_REQUEST['email'] and not $_REQUEST['mail'] (actually, I would avoid using $_REQUEST at all - use the $_POST superglobal, since your form is submitting via POST - but it will work either way).

  7. The Following User Says Thank You to traq For This Useful Post:

    fcuk89 (08-17-2011)

  8. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Quote Originally Posted by traq View Post
    He is using mail(), guys.
    Yeah, you're right, I completely overlooked it.

    Adrian's code is correct, except you want to add in Reply-To into your header so that when you hit the 'Reply' button, it replies to the specified email.

    This should work:
    PHP Code:
    <?php 
    $to 
    "xxx@gmail.com"$name $_REQUEST['name']; $subject "Feedback from customer ".$name."!"
    $email $_REQUEST['mail'] ; 
    $message $_REQUEST['message'] ; 
    $headers "From: $email\r\nReply-To: ".$email
    $sent mail($to$subject$message$headers) ; // <-- right there
    if($sent) {
       print 
    "Your mail was sent successfully. <br/>You will be redirected to the contact us page in 3 seconds"
    } else {
       print 
    "We encountered an error sending your mail"

    ?>
    - Josh

  9. The Following User Says Thank You to JShor For This Useful Post:

    fcuk89 (08-17-2011)

  10. #6
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    THank you all. I have managed to resolve the problem. Appreciate all the help.

Bookmarks

Posting Permissions

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