从PHP脚本发送邮件会导致错误

时间:2009-02-03 02:44:21

标签: php email

我有一个似乎以前可以使用的脚本但不再使用。

脚本运行后显示此消息:

Array (
    [0] => Unrouteable address [1] => -All RCPT commands were rejected with this error:\\
    503-Unrouteable address 503 valid RCPT command must precede DATA
)
Array (
    [0] => Unrouteable address [1] => -All RCPT commands were rejected with this error:\\
    503-Unrouteable address 503 valid RCPT command must precede DATA
)
Array (
    [0] => Unrouteable address [1] => -All RCPT commands were rejected with this error:\\
    503-Unrouteable address 503 valid RCPT command must precede DATA
)

实际功能:

function emailUser($table, $subject, $message) {
    $query = "SELECT * FROM $table";
    $result=mysql_query($query);

    while($row = mysql_fetch_array($result)) {
        $i = 0;

        while($i <= 0) {
            $to = $row['email'];
            $to_all .= '<li>'.$row['email'].'</li>';
            $mail = new htmlMimeMail();
            $mail->setHTML($message);
            $mail->setSubject($subject);
            $mail->setSMTPParams('mail.site.net', 25, 'site.net');
            $mail->setReturnPath("email@site.net");
            $mail->setFrom("email@site.net");

            $mail_result = $mail->send(array($to), 'smtp');

            if (!$mail_result) {
                    print_r($mail->errors);
                    //failure
                } else {
                    //success
                }
            $i++;
        }
    }
    print '<h3>Mail successuly sent to:</h3>';
    print '<ul>'.$to_all.'</ul>';
}

是否有更好的脚本可供使用?也许电子邮件服务器已经改变了?

感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

尝试重新排序以下内容(setHTML在最后):

$mail->setSubject($subject);
$mail->setSMTPParams('mail.site.net', 25, 'site.net');
$mail->setReturnPath("email@site.net");
$mail->setFrom("email@site.net");
$mail->setHTML($message);

答案 1 :(得分:1)

你确定$ row ['email']是正确的列吗?

该错误似乎向我表明该功能正在接收的收件人列表是可疑的。

答案 2 :(得分:0)

你正在使用的这个htmlMimeMail类是什么?你自己写的吗?

这是一个很好的PHP邮件发件人库:SwiftMailer

至于它曾经工作的原因,现在却没有,邮件服务器配置可能会发生变化。这是你的邮件服务器吗?或者它是你的ISP?我怀疑它由于一些垃圾邮件预防机制而改变了它的行为。它可能拒绝SMTP RCPT收件人,因为您首先使用某些方式(例如SMTP之前的POP或经过身份验证的SMTP)尚未登录。