0

If I use the following code, then the form works fine and I am getting form submissions to my email.

<?php

if($_POST["submit"]) {
    $recipient="meemail@gmail.com";
    $subject="New request";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $sender=$_POST["sendername"];
    $senderEmail=$_POST["senderEmail"];
    $message=$_POST["message"];
    $name_title=$_POST["name_title"];   

    $mailBody = "<b>Name:</b> $name_title $sender\n
                 <b>Email:</b> $senderEmail\n\n
                 <b>Message:</b> $message";

    $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
}

if ($mail_sent) {
?>
    <p>Mail sent</p>
<?php } ?>

If I change the $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>"); TO $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>", $headers);, then the form stops working. What is the issue?

closed as off-topic by TheDeadMedic, fuxia Sep 2 '14 at 11:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • This will break in WordPress anyway, because you have to use wp_mail() to give plugins for server setups a chance. – fuxia Sep 2 '14 at 11:24
2

From: is just another mail header. You need to concatenate this with your current $headers and pass it as one argument to mail():

$headers  = "From: $sender <$senderEmail>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

// la de da

mail( $recipient, $subject, $mailBody, $headers );
  • any how it says "unknown sender" tinypic.com/r/2h869g6/8 – Riffaz Starr Sep 2 '14 at 12:32
  • how can I change that to sender name? – Riffaz Starr Sep 2 '14 at 12:36
  • This seems like a server config issue - PHP mail is notoriously variable. You'll have much better luck @ StackOverflow or ServerFault. – TheDeadMedic Sep 2 '14 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.