best practice?
Posted: Mon Feb 19, 2007 3:47 pm
First I would like to offer my thanks to the author for creating this software! 
In my applications, I use phpmailer for mailing list for a while but after stumbling onto swiftmailer, it is miles better - I guess I am moving over from the dark side of phpmailer!
I do have a few queries I would appreciate if you could clarify (using version 3):
1- Any reason why I should use batchSend instead of normal send (with a do loop), e.g.
Is the above code a bad practice or....? The code above is not fully tested and is just based on "theories" and of course would require some anti-flood thing. 
2- The mailing list system uses a HTML template containing placeholders (e.g. [Forename] [Surname]) - I am aware there's a template plugin for swiftmailer and saw this thread but unsure if it is suitable for version 3?
Many thanks in advance.
In my applications, I use phpmailer for mailing list for a while but after stumbling onto swiftmailer, it is miles better - I guess I am moving over from the dark side of phpmailer!
I do have a few queries I would appreciate if you could clarify (using version 3):
1- Any reason why I should use batchSend instead of normal send (with a do loop), e.g.
Code: Select all
ignore_user_abort();
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
// SELECT SQL query here
try {
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("mail.server.com"));
//Create the message
$message =& new Swift_Message("My subject", "Message body");
$From = "from@email.com";
$swift->setReplyTo("contact@email.com");
$i = 1;
do {
$email = $row['emailaddress'];
if($swift->send($message, $email, $From)) {
$sent = 1;
echo "<span style=\"color:#339900;\">$i: " . $email . "</span><br>";
} else {
$sent = 0;
echo "<span style=\"color:#FF0000;\">$i: " . $email . "</span><br>";
}
// do some mySQL stuff here, e.g. UPDATE table SET sent=$sent WHERE...
$i++;
} while ($row = mysql_fetch_assoc($row_set));
$swift->close();
} catch (Swift_Connection_Exception $e) {
echo "There was a problem communicating with SMTP: " . $e->getMessage();
} catch (Swift_Message_MimeException $e) {
echo "There was an unexpected problem building the email:" . $e->getMessage();
}2- The mailing list system uses a HTML template containing placeholders (e.g. [Forename] [Surname]) - I am aware there's a template plugin for swiftmailer and saw this thread but unsure if it is suitable for version 3?
Many thanks in advance.