Send emails with PHP and Swift

Swift is a powerful PHP library to send email messages, much better than using the mail() native function. It offers a very nice set of features, some of these are:

  • Better performance
  • Multiple connection types (basic mail() function, SMTP)
  • Full Mime 1.0, attachments and embed images
  • HTML support
  • Multiple authentication mechanisms
  • many more

It is very popuplar among symfony users.

At ServerGrove we have added this library to all our servers, so now you can use it without having to upload it to the server. Here are the steps to use it:

The library is located in /usr/local/php/Swift and it will kept up to date with new releases.


<?php

require_once "Swift/lib/Swift.php";
require_once "Swift/lib/Swift/Connection/NativeMail.php";

$swift = new Swift(new Swift_Connection_NativeMail("-fyou@example.com"));

if ($swift->send($message, "recipient@example.com", "you@example.com"))
{
echo "Message sent";
}
else
{
echo "Message failed to send";
}

?>

For more information check out the Swift documentation which is pretty good.

12

02 2009

1Trackbacks/Pingbacks

  1. Daily Digest for 2009-02-13 | Pedro Trindade 14 02 09


Your Comment


blog comments powered by Disqus