1

Can anyone point out where am I getting this form wrong? Instead of being able to reply to the "email" from the sender I get the server email.

Here is the php code:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: business.com'; 
    $to = '[email protected]'; 
    $subject = 'A new Message from your website business.com';
    $human = $_POST['human'];
    $headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: ' . $email . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
    } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
    }
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>

and here is the html

<form method="post" action="contact.php" target="contactIframe" name="contact">
    <label>Name</label>
    <input name="name" placeholder="Type Here">
    <label>Email</label>
    <input name="email" type="email" placeholder="Type Here">
    <label>Message</label>
    <textarea name="message" placeholder="Type Here"></textarea></br>
    <label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here"></br></br>
    <input id="submit" name="submit" type="submit" value="Submit">
    <input type="button" name="reset_form" value="Clear" onclick="this.form.reset();">
</form>

Thanks everyone

1 Answer 1

1

You mail function is does not have $headers as additional headers. The code should be...

 if ($human == '4') {                 
    if (mail ($to, $subject, $body, $headers)) { 
       echo '<p>Your message has been sent!</p>';
    }
 }

ref : PHP Mail Function

Sign up to request clarification or add additional context in comments.

3 Comments

Wow...you right, I have missed the, however, there is still somewhere to edit as the addition to the $headers is now triggering the echo error message
Check is you have $body defined in the code... if it is there, then check for server error_log.
Hey Gopakumar, thanks for helping here, the $body tag is in the code as you can see above, I am not sure I can access the server error log though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.