Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


The classic email sending library for PHP

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star half bd79095782ee4930099175e5ce7f4c89fa3ddabcd56fffcc7c74f6f2a2d46b27 (1 ratings)
Rated 4.5 out of 5
Subscribe to updates I use PHPMailer

Statistics on PHPMailer

Number of watchers on Github 10641
Number of open issues 19
Average time to close an issue 3 days
Main language PHP
Average time to merge a PR 2 days
Open pull requests 20+
Closed pull requests 66+
Last commit over 1 year ago
Repo Created almost 8 years ago
Repo Last Updated over 1 year ago
Size 4.43 MB
Organization / Authorphpmailer
Latest Releasev6.0.3
Page Updated
Do you use PHPMailer? Leave a review!
View open issues (19)
View PHPMailer activity
View on github
Fresh, new opensource launches πŸš€πŸš€πŸš€
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating PHPMailer for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


PHPMailer - A full-featured email creation and transfer class for PHP

Build status: Build Status Scrutinizer Quality Score Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

Class Features

  • Probably the world's most popular code for sending email from PHP!
  • Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
  • Integrated SMTP support - send without a local mail server
  • Send emails with multiple To, CC, BCC and Reply-to addresses
  • Multipart/alternative emails for mail clients that do not read HTML email
  • Add attachments, including inline
  • Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
  • SMTP authentication with LOGIN, PLAIN, CRAM-MD5 and XOAUTH2 mechanisms over SSL and SMTP+STARTTLS transports
  • Validates email addresses automatically
  • Protect against header injection attacks
  • Error messages in 47 languages!
  • DKIM and S/MIME signing support
  • Compatible with PHP 5.5 and later
  • Namespaced to prevent name clashes
  • Much more!

Why you might need it

Many PHP developers utilize email in their code. The only PHP function that supports this is the mail() function. However, it does not provide any assistance for making use of popular features such as HTML-based emails and attachments.

Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules - the vast majority of code that you'll find online that uses the mail() function directly is just plain wrong! Please don't be tempted to do it yourself - if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own - try SwiftMailer, Zend/Mail, eZcomponents etc.

The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.


This software is distributed under the LGPL 2.1 license. Please read LICENSE for information on the software availability and distribution.

Installation & loading

PHPMailer is available on Packagist (using semantic versioning), and installation via composer is the recommended way to install PHPMailer. Just add this line to your composer.json file:

"phpmailer/phpmailer": "~6.0"

or run

composer require phpmailer/phpmailer

Note that the vendor folder and the vendor/autoload.php script are generated by composer; they are not part of PHPMailer.

If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the league/oauth2-client package in your composer.json.

Alternatively, if you're not using composer, copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration and load each class file manually:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

If you're not using the SMTP class explicitly (you're probably not), you don't need a use line for the SMTP class.

If you don't speak git or just want a tarball, click the 'zip' button on the right of the project page in GitHub, though note that docs and examples are not included in the tarball.

Legacy versions

PHPMailer 5.2 (which is compatible with PHP 5.0 - 7.0) is no longer being supported for feature updates, and will only be receiving security updates from now on. You will find the latest version of 5.2 in the 5.2-stable branch, and future versions of 5.2 will be tagged with 5.2.x version numbers, so existing composer configs should remain working. If you're using PHP 5.5 or later, we recommend you make the necessary changes to switch to the 6.0 release.

Upgrading from 5.2

The biggest changes are that source files are now in the src/ folder, and PHPMailer now declares the namespace PHPMailer\PHPMailer. This has several important effects read the upgrade guide for more details.

Minimal installation

While installing the entire package manually or with composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need src/PHPMailer.php. If you're using SMTP, you'll need src/SMTP.php, and if you're using POP-before SMTP, you'll need src/POP3.php. You can skip the language folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need src/OAuth.php as well as the composer dependencies for the services you wish to authenticate with. Really, it's much easier to use composer!

A Simple Example

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = ';';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    $mail->setFrom('', 'Mailer');
    $mail->addAddress('', 'Joe User');     // Add a recipient
    $mail->addAddress('');               // Name is optional
    $mail->addReplyTo('', 'Information');

    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;

You'll find plenty more to play with in the examples folder.

That's it. You should now be ready to use PHPMailer!


PHPMailer defaults to English, but in the language folder you'll find numerous (47 at the time of writing!) translations for PHPMailer error messages that you may encounter. Their filenames contain ISO 639-1 language code for the translations, for example fr for French. To specify a language, you need to tell PHPMailer which one to use, like this:

// To load the French version
$mail->setLanguage('fr', '/optional/path/to/language/directory/');

We welcome corrections and new languages - if you're looking for corrections to do, run the PHPMailerLangTest.php script in the tests folder and it will show any missing translations.


Start reading at the GitHub wiki. If you're having trouble, this should be the first place you look as it's the most frequently updated.

Examples of how to use PHPMailer for common scenarios can be found in the examples folder. If you're looking for a good starting point, we recommend you start with the Gmail example.

Note that in order to reduce PHPMailer's deployed code footprint, the examples are no longer included if you load PHPMailer via composer or via GitHub's zip file download, so you'll need to either clone the git repository or use the above links to get to the examples directly.

Complete generated API documentation is available online.

You can generate complete API-level documentation by running phpdoc in the top-level folder, and documentation will appear in teh docs folder, though you'll need to have PHPDocumentor installed. You may find the unit tests a good source of how to do various operations such as encryption.

If the documentation doesn't cover what you need, search the many questions on Stack Overflow, and before you ask a question about SMTP Error: Could not connect to SMTP host., read the troubleshooting guide.


There is a PHPUnit test script in the test folder. PHPMailer uses PHPUnit 4.8 - we would use 5.x but we need to run on PHP 5.5.

Build status: Build Status

If this isn't passing, is there something you can do to help?


Please disclose any vulnerabilities found responsibly - report any security problems found to the maintainers privately.

PHPMailer versions prior to 5.2.22 (released January 9th 2017) have a local file disclosure vulnerability, CVE-2017-5223. If content passed into msgHTML() is sourced from unfiltered user input, relative paths can map to absolute local file paths and added as attachments. Also note that addAttachment (just like file_get_contents, passthru, unlink, etc) should not be passed user-sourced params either! Reported by Yongxiang Li of Asiasecurity.

PHPMailer versions prior to 5.2.20 (released December 28th 2016) are vulnerable to CVE-2016-10045 a remote code execution vulnerability, responsibly reported by Dawid Golunski, and patched by Paul Buonopane (@Zenexer).

PHPMailer versions prior to 5.2.18 (released December 2016) are vulnerable to CVE-2016-10033 a critical remote code execution vulnerability, responsibly reported by Dawid Golunski.

See SECURITY for more detail on security issues.


Please submit bug reports, suggestions and pull requests to the GitHub issue tracker.

We're particularly interested in fixing edge-cases, expanding test coverage and updating translations.

If you found a mistake in the docs, or want to add something, go ahead and amend the wiki - anyone can edit it.

If you have git clones from prior to the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:

git remote set-url upstream

Please don't use the SourceForge or Google Code projects any more; they are obsolete and no longer maintained.


Development time and resources for PHPMailer are provided by, a powerful email marketing system.

Smartmessages email marketing

Other contributions are gladly received, whether in beer , T-shirts , Amazon wishlist raids, or cold, hard cash . If you'd like to donate to say thank you to maintainers or contributors, please contact them through individual profile pages via the contributors page.


See changelog.


  • PHPMailer was originally written in 2001 by Brent R. Matzelle as a SourceForge project.
  • Marcus Bointon (coolbru on SF) and Andy Prevost (codeworxtech) took over the project in 2004.
  • Became an Apache incubator project on Google Code in 2010, managed by Jim Jagielski.
  • Marcus created his fork on GitHub in 2008.
  • Jim and Marcus decide to join forces and use GitHub as the canonical and official repo for PHPMailer in 2013.
  • PHPMailer moves to the PHPMailer organisation on GitHub in 2013.

What's changed since moving from SourceForge?

  • Official successor to the SourceForge and Google Code projects.
  • Test suite.
  • Continuous integration with Travis-CI.
  • Composer support.
  • Public development.
  • Additional languages and language strings.
  • CRAM-MD5 authentication support.
  • Preserves full repo history of authors, commits and branches from the original SourceForge project.
PHPMailer open issues Ask a question     (View All Issues)
  • almost 3 years PHPmailer appears not to be attempting to authenticate SMTP
  • almost 3 years problem dynamically populate "From:" address...
  • almost 3 years POST sendMail.php 504 (Gateway Timeout)
  • almost 3 years Server timeout when recipient's inbox is full
  • almost 3 years phpmailer DKIM problem
  • almost 3 years Multiple addStringAttchment
  • almost 3 years Problem with signed Message
  • almost 3 years Trouble encoding subjects with isMail
  • almost 3 years Error when trying to send the email
  • about 3 years Validity of unquoted space in mail address
  • about 3 years Email Address Validation RFC5322 vs RFC6530
  • about 3 years Duplicate emails being sent out
  • about 3 years DKIM Problem - openssl_sign
  • about 3 years Error- you must provide at least one recipient email address
  • about 3 years SMTP connect() failed
  • about 3 years DKIM fails with attachment
  • about 3 years Return-Path showing UTF-8 string when contais accents
  • about 3 years Mail with attachments viewing on Iphone
  • about 3 years Gmail got suspended after using PHPMailer
  • about 3 years Mail Rejected - TLS Required
  • about 3 years Default encoding charset for PHPMailer 6
  • about 3 years Mail with attachments send to, and unreadable by client
  • about 3 years TURBO Smtp
  • about 3 years Please use annotated or signed tags for releases
  • over 3 years Keep getting error "Message could not be sent.Mailer Error: Could not instantiate mail function."
  • over 3 years Empty atteachments in CC and BCC
  • over 3 years Mailer Error: Could not instantiate mail function.
  • over 3 years Create a diagnostic utility
  • over 3 years Some HTML emails received in Outlook replace every 75th character with an equals (=) sign
  • over 3 years SMTP time limit ($Timeout) fails if server is not responding at all
PHPMailer open pull requests (View All Pulls)
  • Ability to not send to specific recipients using SMTP mailer
  • XOAUTH2 Google Microsoft - 2
  • allow to override the envelope_to (rcpt), but leave the to headers in…
  • More checks for attacments
  • Added support for sending iCal messages in the "alt_attach" mail type
  • my first try on implementing direct send
  • Expose PHPMailer->setListener(callback) to allow tracking send() progress
  • attempt to verify SSL/TLS connections by default
  • phpmailer.lang-mg
  • Diagnose Function
  • Header overwrite support in PHPMailer::addCustomHeader()
  • Switch to UTF-8 default encoding
  • Improving Brazilian Portuguese translation
  • Fixing typos in German translation ('Deppenleerzeichen')
  • Allow DKIM private key to be provided as a string
  • Add getLastTransactionID()
  • composer: phpunit 4.8
  • add shellsafe method tests
  • composer: indicate ctype ext being used
  • Update phpmailer.lang-id.php
PHPMailer questions on Stackoverflow (View All Questions)
  • PHPMailer won't work with account
  • Extra text in mail body when using phpmailer
  • PHPMailer is not working shows bool(false)
  • phpmailer / sendmail returning error "Connection reset by peer"
  • PHPMailer won't send html message
  • PHPMailer Smtp connect failed. Connection Timed Out (110)
  • How to integrate PHPMailer in phpDolphin?
  • PHPMailer doesn't seeem to work on live site, but works on localhost?
  • Phpmailer working fine in localhost But not in server
  • PHPMailer works on localhost, but fails on server
  • PHPMailer set to Newsletter
  • PHPMailer works on localhost but on but not on server
  • PHPMailer include php page as body?
  • PHPMailer smtp connect() failed on ovh server
  • PhpMailer send email without username and password with Windows
  • phpmailer and php5.6 not working with office365
  • how to remove root user from gmail message sent through phpmailer
  • PhpMailer: send a styled html (with divs and images) email from script
  • Setup phpmailer (5.1.14) with DKIM using SMTP (shared hosting)
  • PHPMailer only works on server, doesn't work on localhost
  • PHPmailer gives error CLIENT -> SERVER: EHLO localhost
  • PHPMailer "Could not connect to SMTP host."
  • PHPMailer hosting site using 123-reg
  • Phpmailer use dkim
  • PHPMailer: Sending Failed
  • PHPMailer GoDaddy Server SMTP Connection Refused
  • SMTP Error: Could not connect to SMTP host using PHPMailer
  • Oauth2 gmail SMTP Authentication Error with phpmailer
  • Can't send e-mail using cpanel and phpmailer
  • Email not sending with PHP phpmailer or mail() function on GoDaddy Windows hosting
PHPMailer list of languages used
PHPMailer latest release notes
v6.0.3 PHPMailer 6.0.3
  • Correct DKIM canonicalization of line breaks for header & body - thanks to @themichaelhall
  • Make dependence on ext-filter explicit in composer.json
v6.0.2 PHPMailer 6.0.2

This is a general maintenance release.

  • Don't make max line length depend on line break format
  • Improve Travis-CI config - thanks to Filippo Tessarotto
  • Match SendGrid transaction IDs
  • idnSupported() now static, as previously documented
  • Improve error messages for invalid addresses
  • Improve Indonesian translation (thanks to @januridp)
  • Improve Esperanto translation (thanks to @dknacht)
  • Clean up git export ignore settings for production and zip bundles
  • Update license doc
  • Updated upgrading docs
  • Clarify addStringEmbeddedImage docs
  • Hide auth credentials in all but lowest level debug output, prevents leakage in bug reports
  • Code style cleanup
v5.2.26 PHPMailer 5.2.26
  • Minor security backport from 6.0 - set Debugoutput in constructor according to SAPI in use, avoiding potential XSS in default debug output. Thanks to Bankde Eakasit for spotting it.
Other projects in PHP