user2356283
user2356283

Reputation: 11

contact form is blank; contact form reply goes to wrong address

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 = '[email protected]';

    $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?

Upvotes: 0

Views: 152

Answers (2)

user2433281
user2433281

Reputation: 19

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`?>

Upvotes: 0

Mateusz
Mateusz

Reputation: 3048

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.

Upvotes: 0

Related Questions