batchSend - no of emails sent in one go
Posted: Thu Mar 13, 2008 2:44 am
i m trying to send customized emails to multiple recpnts whose email adresses have been retrieved from db. I am using Decorator plugin and using batchSend to send the messages.Heres my code:
<?php
//Load in the files we'll need
require_once "email_swift/lib/Swift.php";
require_once "email_swift/lib/Swift/Connection/SMTP.php";
require_once "email_swift/lib/Swift/Plugin/Decorator.php";
//Start Swift
//Connect to Gmail (PHP5)
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername('xxx@gmail.com');
$smtp->setPassword('xxx');
$swift =& new Swift($smtp);
//Create the message, using Decorator plugin
$message =& new Swift_Message("Notification for {name}", "your mail id is {emailid}");
$message->setContentType("text/html");
//add recepients
$recipients =& new Swift_RecipientList();
$replacements_temp = array();
do{
$recipients->addTo($row_Recordset1["email_address"]);
//Specify the list of replacements as a 2-d array
$replacements_temp[$row_Recordset1["email_address"]] = array("{name}" => $row_Recordset1['StudentName'], "{emailid}" => $row_Recordset1['email_address']);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$replacements_temp_count = count($replacements_temp);
//original array as in website
$replacements_orig = array(
"joe@bloggs.com" => array("{name}" => "Joe", "{weather}" => "chilly"),
"fred@perry.com" => array("{name}" => "Fred", "{weather}" => "muggy")
);
//comments to understand code starts
//echo "replacements_temp - "; echo "<br>";
//print_r($replacements_temp); echo "<br>"; echo "<br>";
//echo "no of elements in replacements_temp - "; echo $replacements_temp_count; echo "<br>";
//
//
//echo "<br>"; echo "<br>";
//echo "replacements_orig"; echo "<br>";
//print_r($replacements_orig);
//comments ends
//add recepients ends
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements_temp), "decorator");
if ($swift->batchSend($message, $recipients, "xxx@gmail.com")) {
echo "Sent";
}
else {
echo "Failed";
}
?>
With this code, i would like to know that with a server timeout of 30 secs and an internet speed of 2MBPS, how many emails can be sent at one time. I am not able to send more than 6 or 7 emails in one go. Please help me as this number is too low and becoming impractical. What alternatives can i use to send emails to around 100 email ids in one go.
Am thankful for swift, but please help me out
waiting in anticipation
<?php
//Load in the files we'll need
require_once "email_swift/lib/Swift.php";
require_once "email_swift/lib/Swift/Connection/SMTP.php";
require_once "email_swift/lib/Swift/Plugin/Decorator.php";
//Start Swift
//Connect to Gmail (PHP5)
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername('xxx@gmail.com');
$smtp->setPassword('xxx');
$swift =& new Swift($smtp);
//Create the message, using Decorator plugin
$message =& new Swift_Message("Notification for {name}", "your mail id is {emailid}");
$message->setContentType("text/html");
//add recepients
$recipients =& new Swift_RecipientList();
$replacements_temp = array();
do{
$recipients->addTo($row_Recordset1["email_address"]);
//Specify the list of replacements as a 2-d array
$replacements_temp[$row_Recordset1["email_address"]] = array("{name}" => $row_Recordset1['StudentName'], "{emailid}" => $row_Recordset1['email_address']);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$replacements_temp_count = count($replacements_temp);
//original array as in website
$replacements_orig = array(
"joe@bloggs.com" => array("{name}" => "Joe", "{weather}" => "chilly"),
"fred@perry.com" => array("{name}" => "Fred", "{weather}" => "muggy")
);
//comments to understand code starts
//echo "replacements_temp - "; echo "<br>";
//print_r($replacements_temp); echo "<br>"; echo "<br>";
//echo "no of elements in replacements_temp - "; echo $replacements_temp_count; echo "<br>";
//
//
//echo "<br>"; echo "<br>";
//echo "replacements_orig"; echo "<br>";
//print_r($replacements_orig);
//comments ends
//add recepients ends
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements_temp), "decorator");
if ($swift->batchSend($message, $recipients, "xxx@gmail.com")) {
echo "Sent";
}
else {
echo "Failed";
}
?>
With this code, i would like to know that with a server timeout of 30 secs and an internet speed of 2MBPS, how many emails can be sent at one time. I am not able to send more than 6 or 7 emails in one go. Please help me as this number is too low and becoming impractical. What alternatives can i use to send emails to around 100 email ids in one go.
Am thankful for swift, but please help me out
waiting in anticipation