Categories
symfony

Swift mailer

I would like to drop here a couple of lines about Swift mailer.
If you are going to send message to the big number of email recepients it’s obviously you’ll need to write a batch script so it processes this in background. And it would be good to have something (mailer layer) that you can rely one and use for sending out tons of messages, newsletters or maybe even evil spam, why not.

So I’ve looked through Symfony forum and found a couple of posts which say to try SwiftMailer as a solution. And what is also important – there is already done swift bridge plugin for it: sfSwiftPlugin.

Swift is a fully OOP library for sending e-mails from PHP websites and applications. It does not rely on PHP’s native mail() function which is known for using high server resources when sending multiple emails. Instead, Swift communicates directly with an SMTP server or a MTA binary to send mail quickly and efficiently.

Early versions of Swift were comparable to PHPMailer. Swift has since evolved and matured into a fully-fledged object-oriented mailing solution. Compared with PHPMailer, the interface for Swift is both tighter and more intuitive. I genuinely belive that no other mailer comes close to Swift in terms of available features.

Swift supports event-driven plugins which offer you the opportunity to really take control of the library and set this mailer apart from everything else that’s out there. Over time, and from previous versions, the library has been steadily refactored and is now usable for more than just the blind sending of emails. It can compose RFC 2822 compliant messages for use elsewhere too. I’m looking at offering the reverse and parsing real emails into the message object format used in the library.

I refer you to swift doc so you can get more ideas how to built a site with it and which features it has http://www.swiftmailer.org/wikidocs/

Ok, so all you need to start it up is to add these lines to your batch script:

$swift =& new Swift(new Swift_Connection_SMTP(smtp_server_address));
$recipients =& new Swift_RecipientList();
$message =& new Swift_Message($email_subject, $email_body);
foreach ($addresses as $address) $recipients->addTo($address);
$swift->batchSend($message, $recipients, $from_email_address);

and go ahead with it! Interesting to know if someone has ever used Swift in production and what is performance and how it works for big amount of addresses. I can’t find such info on web.