1

这是失败的代码:

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

它完美地工作。

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

4

1 回答 1

0

我认为@localhost被添加到你的$email变量中Mail.php

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

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

于 2012-05-04T15:20:27.443 回答