batch->send() failing
Posted: Mon Jan 28, 2008 11:58 pm
Swift 3.3.2
PHP 5.2.3
SMTP
I'm having this issue where sending a batch email seems to hang after sending to 39 users. I've checked with the web host to make sure there aren't any issues on their end and that I'm not violating any throttling limits. I've used this code in the past but we've recently switched hosts (Dreamhost) and upgraded to PHP5 (GO PHP 5!) so I might just be missing something in the transition.
You can see below that I'm using VerboseSending to help see whats going on. I am sending 48 messages every 900 seconds to ensure that I don't pass a 200/hour limit. Several minutes after sending, I see the VerboseSending output for 39 people and processing appears to end (ie. "Done" message in Firefox browser and the text that should appear after the VerboseSending never gets rendered to the page).
Any suggestions of what I might look for to help the issue would be greatly appreciated. I've tried to do as much homework as possible before sending this message and am running out of ideas. I have not ruled out possibilities other than Swift but someone else's eyeballs on my code just might help me out.
The following code has some extra html junk filtered out to help you read the Swift Mailer parts. If you'd prefer the original just say the word.
Thanks in advance. I greatly value your product and your time!
PHP 5.2.3
SMTP
I'm having this issue where sending a batch email seems to hang after sending to 39 users. I've checked with the web host to make sure there aren't any issues on their end and that I'm not violating any throttling limits. I've used this code in the past but we've recently switched hosts (Dreamhost) and upgraded to PHP5 (GO PHP 5!) so I might just be missing something in the transition.
You can see below that I'm using VerboseSending to help see whats going on. I am sending 48 messages every 900 seconds to ensure that I don't pass a 200/hour limit. Several minutes after sending, I see the VerboseSending output for 39 people and processing appears to end (ie. "Done" message in Firefox browser and the text that should appear after the VerboseSending never gets rendered to the page).
Any suggestions of what I might look for to help the issue would be greatly appreciated. I've tried to do as much homework as possible before sending this message and am running out of ideas. I have not ruled out possibilities other than Swift but someone else's eyeballs on my code just might help me out.
The following code has some extra html junk filtered out to help you read the Swift Mailer parts. If you'd prefer the original just say the word.
Code: Select all
<?
require_once $_SERVER['DOCUMENT_ROOT']."/lib/php/core.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift/Log.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift/Connection/SMTP.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift/Plugin/AntiFlood.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift/Plugin/VerboseSending.php";
require_once $_root."/lib/php/swift_3_3_2/lib/Swift/Plugin/VerboseSending/DefaultView.php";
require('lister_lib.php');
$list = array();
$header = $dir_img."/email_hdr_600.png";
$footer = $dir_img."/email_ftr_580.jpg";
$css_msg_start = "<p style=\"width:580px;\">";
$css_disc_start = "<p style=\"width:580px;font-size-adjust:.40; color:#666;\">";
$css_end = "</p>";
$fromname = "Communication & Information Team";
$fromemail = "communication@mycompany.org";
$disclaimer = "My disclaimer";
define("ANTI_FLOOD_COUNT", 48); // number of emails per iter
define("ANTI_FLOOD_DELAY", 900); // delay between iters in seconds
####### GET ADDRESS LIST FROM DB ###########
$l = get_active_group();
$list = create_email_list($l);
####### SET UP DISK CACHING FOR MEMORY IMPROVEMENTS WITH IMAGES/ATTACHMENTS ##############
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
####### SET UP LOGGING #############
$mailer_log_level = Swift_Log::LOG_EVERYTHING;
$mailer_log =& Swift_LogContainer::getLog();
$mailer_log->setLogLevel($mailer_log_level);
$mailer_log->setMaxSize(200); // default = 50
####### SET UP VERBOSE SENDING #############
$view =& new Swift_Plugin_VerboseSending_DefaultView();
####### SET UP SMTP CONNECTION #############
$smtp = new Swift_Connection_SMTP('mail.mycompany.org');
$smtp->setUsername("communication@mycompany.org");
$smtp->setPassword("some_password");
$mailer =& new Swift($smtp);
####### LOAD PLUGINS #######################
$mailer->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
$mailer->attachPlugin(new Swift_Plugin_AntiFlood(ANTI_FLOOD_COUNT, ANTI_FLOOD_DELAY), "anti-flood");
$batch=& new Swift_BatchMailer($mailer);
$message =& new Swift_Message($subj);
###### THE TEXT PART ######
$plain_part = strip_tags($msg). "\r\n" . $disclaimer;
$message->attach(new Swift_Message_Part($plain_part));
###### THE HTML PART ######
$msg = $css_msg_start . $msg . $css_end;
$disclaimer = $css_disc_start . $disclaimer . $css_end;
$html_part =& new Swift_Message_Part( "<img src=\"" . $message->attach(new Swift_Message_Image(new Swift_File($header))) . "\" alt=\"\" />" .$msg . "<p /><img src=\"" . $message->attach(new Swift_Message_Image(new Swift_File($footer))) . "\" alt=\"\" />" . "<p />" . $disclaimer, "text/html");
$message->attach($html_part);
###### THE ATTACHEMENT(S) ######
for ($i=0; $i<2; $i++)
{
if ( $_FILES['f']['error'][$i] == 0 )
{
echo 'Add Attachment: '.$_FILES['f']['name'][$i].'<br />';
$message->attach(new Swift_Message_Attachment( new Swift_File($_FILES['f']['tmp_name'][$i]),
$_FILES['f']['name'][$i],
$_FILES['f']['type'][$i]));
}
}
//Make the script run until it's finished in the background
set_time_limit(0); ignore_user_abort();
flush();
if ( defined('MBLAST_DEBUG') )
{
echo "<pre>";
print_r($message->headers->get("To"));
echo "</pre>";
}
else
{
####### SEND THE EMAIL #####################
$recipients =& new Swift_RecipientList();
foreach ($list as $addr)
$recipients->addTo($addr[0], $addr[1]);
$from = new Swift_Address($fromemail, $fromname);
$num_sent = $batch->send($message, $recipients, $from);
echo '<p />=========> '; ?><span class="green"><?echo "Mail job has completed"; ?></span><? echo ' <==========<p />';
echo "Message sent to ". $num_sent." of ". count($list) ." recipients<p />";
if ( count($batch->getFailedRecipients()) )
{
echo "<strong>Failed recipients:</strong><br />";
echo implode("<br>", $batch->getFailedRecipients());
}
echo '<p />=========> Log Messages (if any) are below <==========<p />';
echo "<pre>" . $mailer_log->dump(true) . "</pre>";
}
?>