我正在尝试使用此脚本发送电子邮件
$to = 'example@example.com';
$headers['To'] = $to;
$headers['From'] = '"My Name" <examlpe@example.com>';
$headers['Return-Path'] = 'examlpe@example.com';
$headers['Subject'] = 'Subject';
$auth = array('host' => MAIL_HOST, 'auth' => true, 'username' => MAIL_USER, 'password' => MAIL_PASS);
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail))
echo('<p>PEAR mail: '.$mail->getMessage().'</p>');
else
echo('<p>PEAR mail: Message successfully sent!</p>');
但我收到以下消息:
Failed to set sender: "My Name" <example@example.com> [SMTP: Invalid response code received from server (code: 501, response: <"My Name" <example@example.com>>: "@" or "." expected after ""My Name"")]
当我像这样制作from字段时:
$headers['From'] = 'examlpe@example.com';
它工作正常,我收到了电子邮件.
如何发送包含发件人姓名的电子邮件?
解决方法:
Return-Path和Reply-To不一样.
返回路径:如果要覆盖电子邮件的信封发件人,请设置Return-Path标头,将使用该值而不是From:标头(来自PEAR网站)的值.您不能为Return-Path设置名称,只能设置电子邮件地址.
回复:使收件人回复此地址.您可以设置名称和电子邮件地址.
因此,通过Reply-To替换Return-Path,它将起作用.