batchSend - no of emails sent in one go

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
sahaishivam
Forum Newbie
Posts: 4
Joined: Mon Mar 10, 2008 1:40 pm

batchSend - no of emails sent in one go

Post by sahaishivam »

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

Re: batchSend - no of emails sent in one go

Post by Chris Corbyn »

I'm not sure there's much I can do. It's certainly not the code.... sounds like really bad network latency issues. You could try a different SMTP server. People send up to 10 emails per second quite happily so it's certainly nothing you can change at a code level.
sahaishivam
Forum Newbie
Posts: 4
Joined: Mon Mar 10, 2008 1:40 pm

Re: batchSend - no of emails sent in one go

Post by sahaishivam »

ya as u said it might b smtp issue..but theres a drastic performance diff when using send() and batchSend(). Am easily sending good no of emails using send(), but then they arent personalized. Can u suggest me apart from gmail which smtp (free) servers can i use to get to the root of my problem. nd one more thing, do ppl send 10 emails per sec using batchSend() ?

Waitin for ur reply...nd hey u r doin a really gud job
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: batchSend - no of emails sent in one go

Post by Chris Corbyn »

sahaishivam wrote:ya as u said it might b smtp issue..
Since you're using Gmail it's not going to be that fast, but at 6/7 emails before it times out it's more likely to be a network issue.
but theres a drastic performance diff when using send() and batchSend().
?
Am easily sending good no of emails using send(), but then they arent personalized.
Do you mean just replacing the call to batchSend() with send()? They do different things. With send() the message will be sent with all the recipients in the To: header, with batchSend() each recipient gets their own message with their own To: header.
Can u suggest me apart from gmail which smtp (free) servers can i use to get to the root of my problem.
I'm afraid not. Sending emails is a high bandwidth process and is easily subject to being abused by spammers. No companies that I'm aware of offer truely free email sending from your own domain over SMTP. There are companies you can use for roughly $1000/yr however.
nd one more thing, do ppl send 10 emails per sec using batchSend() ?
Yes, but it's entirely dependant on your network capabilities and the SMTP server capabilities.
...nd hey u r doin a really gud job
Thanks :D
Post Reply