php - mail() function wont work properly

977

I have to following code that works but not the way i want it

if(isset($_POST['edit']) && $_POST['edit']!="")
{
    // Email Information
    $firstName = $_POST['fname'];
    $lastName = $_POST['lname'];
    $mobile = $_POST['contactNumber'];
    $comments = $_POST['message'];
    $email_from = $_POST['email'];
    $email_to = "[email protected]";
    //$email_headers = "From: ". $firstName ." ". $lastName . " <" . $email_from . ">\r\n" . "Reply-To: [email protected]";
    $email_headers = "From: $firstName $lastName <[email protected]>" . "\r\n" . "Reply-To: [email protected]";


    $email_subject = "Munster Wedding DJs Inquiry!";
    $email_body = "\nName: " . $firstName . " " . $lastName .
    "\nEmail: " . $email_from . 
    "\nPhone Number: " . $mobile . 
    "\nMessage: " . $comments;

    // Send Email
    $mailerResult = @mail($email_to, "$email_subject", $email_body,
    $email_headers, '-f ' . $email_from);

    // Check For Errors
    if($mailerResult) {

        //echo "Mail Sent!";
        echo '<script>document.location.href="thanks.html#anchor"</script>';
        exit();

    } else {

        //  echo "Error Sending Email!" . "<br><br>";
        //  print_r(error_get_last());
    }

}

If I change

From: $firstName $lastName <[email protected]>"

to

From: $firstName $lastName <$email_from>" 

The form doesnt send an email? Why is this?

All i want to do is recieve the email and when i click reply it put users email address into the "to" field.

822

Answer

Solution:

Try using like this, &lt ; for < &gt ; for >

remove the space between &lt and ;

$email_headers = "From: $firstName $lastName &lt; $email_from &gt;" . "\r\n" . "Reply-To: [email protected]";

People are also looking for solutions to the problem: php - Why is query_posts causing an infinite loop here?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.