What are the Swift Mailer limits?

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
Thunderbite
Forum Newbie
Posts: 2
Joined: Thu Nov 08, 2007 6:31 am

What are the Swift Mailer limits?

Post by Thunderbite »

Hi everybody,

Im trying to write a "simple" mailing script for my customers so that they can send easaly newsletters and that kind of stuff.

The biggest mailing list there is at the moment contains about 900 subscribers.

In the swift mailer i used the Batchsend option in the following order:

Code: Select all

//Loading the newsletter from the db
$brief_sql = "SELECT * FROM tb_cms_nieuwsbrief_brieven WHERE id='" . $_POST['brief_id'] . "'";
$brief_result = mysql_query($brief_sql);
while($brief = mysql_fetch_array($brief_result)) {
				
//Loading users from the db
$user_sql = "SELECT * FROM tb_cms_nieuwsbrief_settings WHERE id=1";
$user_result = mysql_query($user_sql);
while($user = mysql_fetch_array($user_result)) {
			
//Load in the files we'll need
require_once "../mailer/lib/Swift.php";
require_once "../mailer/lib/Swift/Connection/SMTP.php";
require_once "../mailer/lib/Swift/Plugin/Throttler.php";
				 
$smtp =& new Swift_Connection_SMTP("localhost", 25);
$swift =& new Swift($smtp);
				
$throttler =& new Swift_Plugin_Throttler();
$throttler->setEmailsPerMinute(30); //Max of 1 email every 2 seconds
$swift->attachPlugin($throttler, "throttler");
				 				
//Make titel
$message =& new Swift_Message("" . $brief['brief_titel'] . "");
 
//Plain tekst if there is no html
$message->attach(new Swift_Message_Part("" . $user['platte_tekst'] . "

" . $user['website_url'] . "/nieuwsbrief_bekijk.php?nieuwsbrief_id=" . $brief['id'] . " 

Met vriendelijke groet,
" . $user['naam'] .""));
				
//HTML part!
$brief_inhoud = htmlspecialchars_decode($brief['brief_inhoud']);
$message->attach(new Swift_Message_Part($brief_inhoud, "text/html"));
								
$recipients =& new Swift_RecipientList();
				
//Ontvangers van de nieuwsbrief
$ontvng_sql = "SELECT * FROM tb_cms_nieuwsbrief_users WHERE user_actief=1 ORDER BY id";
$ontvng_result = mysql_query($ontvng_sql);

while($ontvng = mysql_fetch_array($ontvng_result)) {
				
$recipients->addTo($ontvng['user_email']);
				
}//Einde ontvangers
				
if ($num_sent = $swift->batchSend($message, $recipients, new Swift_Address($user['email_van'], $user['email_naam']))){
				 
$mailer = "De nieuwsbrief is succesvol verzonden aan $num_sent adressen.";
					
$datum = date("d-m-Y");
				
mysql_query("INSERT INTO tb_cms_nieuwsbrief_history (brief_titel, brief_inhoud, group_naam, datum, aantal) VALUES ('" . $brief['brief_titel'] . "', '" . $brief['brief_inhoud'] . "', 'Alle inschrijvingen', '$datum', '$num_sent')");	
					
} else {
				
$mailer = "Er is een onbekende fout opgetreden bij het verzenden!";

}
				
}
				
}
As you can see im using also the Throttler plugin to send 30 mails in one minut to lower the load on the smtp server.

My questions....

Is this a good way to use the Swiftmailer?

Is there any limit in the number of sending mailings like this? so is it possible to send about 900/1000 emails in this way?

Thanks for the help!
Mark
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

There's no limit from Swift's point of view, but there probably is a limit from the SMTP server's point of view. I'd usually suggest disconnecting and pausing for a brief while after each 100 emails sent. The AntiFlood plugin does that (say 30 second pause every 100 emails).
Thunderbite
Forum Newbie
Posts: 2
Joined: Thu Nov 08, 2007 6:31 am

Post by Thunderbite »

Thanks Chris,

That sounds great i will try that approach!
Post Reply