【发布时间】:2012-03-09 04:46:09
【问题描述】:
我正在尝试使用此脚本发送电子邮件
$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';
它工作正常,我收到了电子邮件。
如何发送带有发件人姓名的电子邮件?
【问题讨论】:
-
你试过无引号吗?
My Name <example@example.com>也是一个有效的邮箱。