I have a problem using PHP to send mail. The mail is received by Outlook correctly, but it does not show the "From" address in the e-mail.
$subject = $_POST['message_subject'];
$message = $_POST['speaker_description'];
$email = $_POST['email'];
$option = $_POST['sel_reg_options'];
$email = substr_replace($email ,"",-1);
$headers .= "Content-type: text/html; charset=iso-8859-1
";
$headers .= "From:My Name<myifno@mysite.com>
";
$headers .= "Reply-To: Registration of Interest<info@mysite.com>
";
$headers .= "MIME-Version: 1.0"."
";
$mail_sent = @mail($email,$subject,$message,$headers);
You should enclose the name in double quotes (this also applies to the Reply-To address name):
$headers .= "From: \"My Name\" <myifno@mysite.com>
";
Also, if running PHP on Unix, add the FROM envelope to the $additional_parameters
parameter:
$mail_sent = @mail($email,$subject,$message,$headers,'-f myifno@mysite.com');
On the contrary, if running on Windows, set the sendmail_from
INI directive either in php.ini
or by using:
ini_set('sendmail_from', 'myifno@mysite.com');
Sources: RFC2822, php.net user comment, IBM sendmail command reference
I just recently switched my email scripts to PHPMailer. It has made creating and sending emails much easier. I no longer worry about incorrect headers and the intricacies around PHP and email. I haven't had any issues formatting emails so that they are received correctly in the several email clients out there either.