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!";
}
}
}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