Still stumped - Help please

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
cybercog
Forum Newbie
Posts: 20
Joined: Sat Oct 06, 2007 10:35 pm

Still stumped - Help please

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post 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?
cybercog
Forum Newbie
Posts: 20
Joined: Sat Oct 06, 2007 10:35 pm

Post 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
cybercog
Forum Newbie
Posts: 20
Joined: Sat Oct 06, 2007 10:35 pm

Post by cybercog »

Well, by switching to batchSend the problem is gone no matter what the address.

Very cool.

Thanks
Post Reply