0

Am trying to make a captcha-free, spam blocking contact form. From the user's point of view, it appears to be working since the thank-you page appears after the send button is clicked.

Problem #1: The email that arrives is blank, containing none of the content of the message that was sent. Found a post here that sounds similar, but the suggestion offered didn't apply: Contact form problem - I do receive messages, but no contents (blank page).

Problem #2: The reply message also shows up in that same inbox instead of being sent to the form user's address--which when testing, is my own.

The HTML:

<form method="post" action="submit.php">
 <p>Name:<br>
 <input type="text" name="Name" id="Name" /></p>

 <p>Phone:<br>
 <input type="text" name="Phone" id="Phone" /></p>

 <p>Email:<br>
 <input type="text" name="Email" id="Email" /></p>

 <p class="antispam">Leave this empty:<br />
 <input name="url" /></p>

 <p style="color:#06C;">Forward to:<br>
 <input type="text" name="Forwardto" id="Forwardto" /></p>

 <p>Message:<br />
 <textarea name="Message" rows="20" cols="20" id="Message"></textarea></p>

 <p><input type="submit" value="Send" class="submit-button" /></p>
</form>

The PHP (with my actual address removed):

<?php

if(isset($_POST['url']) && $_POST['url'] == ''){

    $youremail = '----@----.com';

    $body = "This is the form that was just submitted:
    Name:  $_POST[name]
    Phone:  $_POST[phone]
    E-Mail: $_POST[email]
    Forward to: $_POST[forwardto]
    Message: $_POST[message]";

    if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
      $headers = "From: $_POST[email]";
    } else {
      $headers = "From: $youremail";
    }

    mail($youremail, 'Contact Form', $body, $headers );

}

?>

The relevant CSS:

<style type="text/css">
.antispam { display:none;}
</style>

Is the problem in the code above . . . or could something else be going on?

Community
  • 1
  • 1
  • 5
    Have you tried using `$_POST['Email']` instead of `$_POST['email']` - capital "E"? – Mateusz May 09 '13 at 14:39
  • You should also turn on error reporting, you would have been given php notices that the $_POST indexes you were using were invalid – Patrick Evans May 09 '13 at 14:48
  • php array keys are case sensitive. all of your $_POST keys MUST match the casing of the `name` in the form. you're submitting `Email`, `Phone`, etc... but are attempting to access `email`, `phone`, etc... – Marc B May 09 '13 at 14:51

2 Answers2

0

You're trying to access $_POST['email'] while the field's name is email (small "e") - try using $_POST['Email'] instead

Second problem - mail() function's first argument is the email onto which you want it to be sent, i.e. $_POST['Email']. Right now you're trying to send it into hard-coded $youremail.

Mateusz
  • 3,038
  • 4
  • 27
  • 41
  • It's not just the email variable that's wrong. They'll all improperly cased. – j08691 May 09 '13 at 14:42
  • Thanks to all of you for your replies. Those corrections have taken care of both problems. – user2356283 May 09 '13 at 19:31
  • If I helped you, please accept and upvote my answer. For error reporting take a look [here](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php). – Mateusz May 09 '13 at 19:34
  • @Mateusz: I did try to earlier, but it won't let me because I don't have the minimum required reputation of 15. – user2356283 May 09 '13 at 19:52
0

first you need to close the quote $body = "This is the form that was just submitted:"; i say to use $_REQUEST instead of $_POST as this variable is a superglobal Array used to collect data sent with both the GET and POST methods. i have tried this and it works if (isset($_REQUEST['email'])) enter code here`{

      //Email information
      $admin_email = "myemail.co.uk";
      $subject = "This is the form that was just submitted";
      $email = $_REQUEST['email'];
      $comment = $_REQUEST['comment'];
      $full_name = $_REQUEST['full_name'];

      //send email
      mail($admin_email, "$subject", "message:" . $comment, "From:" . $email,     `enter code here`enter code here`$full_name);

       //Email response if needed
      echo "Thank you for contacting us!";
       }

      //if "email" variable is not filled out, display the form
       else  
        {
        enter code here`enter code here`?>
        enter code here`<p>Email us at <i>website name.com</i></p>
        enter code here`<?php
        enter code here`}
        enter code here`die();
        enter code here`?>