我正在尝试使用这个脚本发送电子邮件。
当我将表单字段设置为以下内容时:
$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"")]
当我将表单字段设置为以下内容时:
$headers['From'] = 'examlpe@example.com';
它能正常工作并且我收到了邮件。
如何发送带有发件人名称的电子邮件?
My Name <example@example.com>
也是一个有效的邮箱。 - Alexander