Swift Mailer is a component based library for sending e-mails from PHP applications.

System Requirements

Swift Mailer requires PHP 7.0 or higher (proc_* functions must be available).

Swift Mailer does not work when used with function overloading as implemented by mbstring when mbstring.func_overload is set to 2.


The recommended way to install Swiftmailer is via Composer:

$ composer require "swiftmailer/swiftmailer:^6.0"

Basic Usage

Here is the simplest way to send emails with Swift Mailer:

require_once '/path/to/vendor/autoload.php';

// Create the Transport
$transport = (new Swift_SmtpTransport('', 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(['[email protected]' => 'John Doe'])
  ->setTo(['[email protected]', '[email protected]' => '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');

Getting Help

For general support, use Stack Overflow.

For bug reports and feature requests, create a new ticket in GitHub.

« Table of Contents

Questions & Feedback


Creative Commons License Swiftmailer documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.