php邮件与outlook无法完美配合

我使用
PHP发送邮件时遇到问题. Outlook正确接收邮件,但它不显示电子邮件中的“发件人”地址.

$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<myifno@mysite.com>\r\n";
$headers .= "Reply-To: Registration of Interest<info@mysite.com>\r\n";          
$headers .= "MIME-Version: 1.0"."\r\n";
$mail_sent = @mail($email,$subject,$message,$headers);

最佳答案 您应该将名称括在双引号中(这也适用于Reply-To地址名称):

$headers .= "From: \"My Name\" <myifno@mysite.com>\r\n";

此外,如果在Unix上运行PHP,请将FROM信封添加到$additional_parameters参数:

$mail_sent = @mail($email,$subject,$message,$headers,'-f myifno@mysite.com');

相反,如果在Windows上运行,请在php.ini中设置sendmail_from INI指令,或者使用:

ini_set('sendmail_from', 'myifno@mysite.com');

资料来源:RFC2822,php.net user comment,IBM sendmail command reference

点赞