PEAR :: Mail'未能添加收件人'

时间:2012-05-04 15:14:36

标签: php email smtp pear

这是失败的代码:

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>';

效果很好。

谁能告诉我我错过了什么?

1 个答案:

答案 0 :(得分:0)

我认为@localhost已添加到$email

中的Mail.php变量中

尝试更改脚本中$email变量的名称。

此外,您可以在脚本中使用die($email);来测试不同阶段的电子邮件的价值。