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

问题描述 投票:0回答:3

我有一个似乎以前工作但不再工作的脚本。

它在脚本运行后显示此消息:

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 protected]");
            $mail->setFrom("[email protected]");

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

有更好的脚本可供使用吗?也许电子邮件服务器已更改?

任何帮助表示赞赏。

php email
3个回答
1
投票

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

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

1
投票

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

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


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.