0

I have a script that seemed to work before but no longer does.

It is displaying this message after the script runs:

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
)

The actual function:

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

Is there a better script to use? Maybe the email server has changed?

Any help is appreciated.

1
  • The first thing that comes to mind is to check the validity of the email address. However, above and beyond this, what is the purpose of the inner while loop ("$i <=0") - it seems completely spurious and that loop will only execute once anyways. Commented Feb 3, 2009 at 3:33

3 Answers 3

1

Try reordering to the following (setHTML is at the end):

$mail->setSubject($subject);
$mail->setSMTPParams('mail.site.net', 25, 'site.net');
$mail->setReturnPath("[email protected]");
$mail->setFrom("[email protected]");
$mail->setHTML($message);
Sign up to request clarification or add additional context in comments.

2 Comments

that did the job. But I did receive a timeout error, but the emails went thru. Maybe I should go about sending a mass email better.
Interesting. I find it strange that the order of arguments would cause a problem. I've used/currently use PEAR:Mail and it's worked out quite well for me.
1

Are you sure that $row['email'] is the correct column?

The error seems to indicate to me that the recipient list that the function is receiving is suspect.

Comments

0

what is this htmlMimeMail class that you're using? did you write it yourself?

This is a good mail sender library for PHP: SwiftMailer

As for the reason why it used to work and now it doesn't, it's probable that the mail server configuration changed. Is it your mail server? Or is it your ISP's? I suspect that it changed its behaviour due to some spam prevention mechanism. It might be rejecting the SMTP RCPT recipients because, say, you haven't logged in first using some means (like POP before SMTP, or authenticated SMTP).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.