Swift Mailer is a component based library for sending e-mails from PHP applications.
Swift Mailer will stop being maintained at the end of November 2021.
Please, move to Symfony Mailer at your earliest convenience. Symfony Mailer is the next evolution of Swift Mailer. It provides the same features with support for modern PHP code and support for third-party providers.
Swift Mailer supports PHP 7.0 to PHP 8.1 included (
proc_* functions must be
Swift Mailer does not work when used with function overloading as implemented
mbstring.func_overload is set to
The recommended way to install Swiftmailer is via Composer:
$ composer require "swiftmailer/swiftmailer:^6.0"
Here is the simplest way to send emails with Swift Mailer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
require_once '/path/to/vendor/autoload.php'; // Create the Transport $transport = (new Swift_SmtpTransport('smtp.example.org', 25)) ->setUsername('your username') ->setPassword('your password') ; // Create the Mailer using your created Transport $mailer = new Swift_Mailer($transport); // Create a message $message = (new Swift_Message('Wonderful Subject')) ->setFrom(['firstname.lastname@example.org' => 'John Doe']) ->setTo(['email@example.com', 'firstname.lastname@example.org' => 'A name']) ->setBody('Here is the message itself') ; // Send the message $result = $mailer->send($message);
You can also use Sendmail as a transport:
// Sendmail $transport = new Swift_SendmailTransport('/usr/sbin/sendmail -bs');