Reputation: 97
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\r\n";
$headers .= "From:My Name<[email protected]>\r\n";
$headers .= "Reply-To: Registration of Interest<[email protected]>\r\n";
$headers .= "MIME-Version: 1.0"."\r\n";
$mail_sent = @mail($email,$subject,$message,$headers);
Upvotes: 5
Views: 1094
Reputation: 2046
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.
Upvotes: 0
Reputation: 911
You should enclose the name in double quotes (this also applies to the Reply-To address name):
$headers .= "From: \"My Name\" <[email protected]>\r\n";
Also, if running PHP on Unix, add the FROM envelope to the $additional_parameters
parameter:
$mail_sent = @mail($email,$subject,$message,$headers,'-f [email protected]');
On the contrary, if running on Windows, set the sendmail_from
INI directive either in php.ini
or by using:
ini_set('sendmail_from', '[email protected]');
Sources: RFC2822, php.net user comment, IBM sendmail command reference
Upvotes: 2