这是失败的代码:
require_once "Mail.php";
$host = "mail.domain.com";
$username = "USER";
$password = "PASS";
$mailto = $name . ' <' . $email . '>';
$subject = 'My Subject';
$from = 'Client Name <info@clientdomain.com>';
$headers = array (
'From' => $from,
'To' => $mailto,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array (
'host' => $host,
'port' => '25',
'auth' => true,
'username' => $username,
'password' => $password
)
);
$mail = $smtp->send($mailto, $headers, $msg);
if (PEAR::isError($mail)) {
echo '<br /><br />' . $mail->getMessage();
} else {
echo '<br /><br />Worked';
}
我将 $email 值传递给脚本,如下所示:
$name = 'Joe Schmoe';
$email = 'webmaster@domain.com';
include ($_SERVER['DOCUMENT_ROOT'] . '/path/to/my/code/above.php');
当我运行脚本时,我收到以下错误:
Failed to add recipient: webmaster@domain.com@localhost
[SMTP: Invalid response code received from server
(code: 504, response: 5.5.2 :
Recipient address rejected: need fully-qualified address)]
如果我将 $mailto 变量从:
$mailto = $name . ' <' . $email . '>';
...到以下内容:
$mailto = $name . ' <webmaster@domain.com>';
它完美地工作。
谁能告诉我我错过了什么?