Page 1 of 1

Still stumped - Help please

Posted: Wed Oct 10, 2007 4:20 am
by cybercog
I can make swift work perfectly during testing, until I try to use it like this: (I've change the real values for privacy)

This script runs perfectly until i add the:

Code: Select all

if($swift->send($message, $ml_email, $from_email)) echo "Sent";
    else echo "Failed";
Then I get this nasty error:
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'There was a problem reading line 1 of an SMTP response. The response so far was:
[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0) ' in /home/dstefani/public_html/swift_lib/Swift/Connection/SMTP.php:250 Stack trace: #0 /home/dstefani/public_html/swift_lib/Swift.php(306): Swift_Connection_SMTP->read() #1 /home/dstefani/public_html/swift_lib/Swift.php(386): Swift->command('RCPT TO: send(Object(Swift_Message), 'noname@noname.c...', 'don@server.com') #3 {main} thrown in /home/don/public_html/swift_lib/Swift/Connection/SMTP.php on line 250

Code: Select all

<?php
$dblink = db_connect();

//Load in the files we'll need
require_once "swift_lib/Swift.php";
require_once "swift_lib/Swift/Connection/SMTP.php";
$swift = new Swift(new Swift_Connection_SMTP("mail.server.com"));

$from_email = 'don@server.com';
$mail_success = 0;
$mail_failure = 0;
$mail_count = 0;
$failure_list = array();
$today = date("Y-m-d");

$sql = "SELECT nl_subject, nl_text FROM newsletter_tool WHERE nl_id = 1";
if(!$results = mysql_query($sql, $dblink)) die( mysql_error() . "<p>Newsletter: $sql</p>");

$nl = mysql_fetch_object($results);
$mail_subject = $nl->nl_subject;
$mail_body = $nl->nl_text;

$message = new Swift_Message($mail_subject, $mail_body);
$message->setReturnPath($from_mail);

$email_array = array();

$email_array[] = 'email_one@gmail.com';
$email_array[] = 'email_two@gmail.com';
$email_array[] = 'email_three@server.com';
$email_array[] = 'noname@noname.com';
$email_array[] = 'somename@somename.com';

foreach($email_array AS $ml_email) {

    print "$ml_email<br />\n";
    if($swift->send($message, $ml_email, $from_email)) echo "Sent";
    else echo "Failed";

}



?>
Thanks,

- Don

Posted: Wed Oct 10, 2007 4:52 am
by Chris Corbyn
How many emails are you sending? This type of thing happens when you send too many emails through a single connection. If it's not based on rates (i.e. emails in a period of time) then the AntiFlood plugin is the solution. If it is based on rates you'll need to throw in the Throttler plugin too ;)

Posted: Wed Oct 10, 2007 4:55 am
by chuckl
Does your SMTP server require authentication of any sort, and are the destination mail server details correct?

If you use telnet to connect to the server - telnet mail.server.com 25 - do you get an SMTP response?

Posted: Wed Oct 10, 2007 5:08 am
by cybercog
I'm testing by sending the five emails in the email_array();
In my real list of email the first three are real and the last two are made up, not real domains.

If I remove those two made up ones, then it works fine.

I'm concerned that if email address like this are going to try and be sent, the script will hang up.

Thanks,

- Don

PS: Its 4:00 AM here, and I've yet to sleep... please excuse any 8O

Posted: Wed Oct 10, 2007 5:23 am
by cybercog
Well, by switching to batchSend the problem is gone no matter what the address.

Very cool.

Thanks