2017 © Pedro Pelรกez
 

library phpmailer

PHPMailer is a full-featured email creation and transfer class for PHP

image

phpmailer/phpmailer

PHPMailer is a full-featured email creation and transfer class for PHP

  • Wednesday, June 27, 2018
  • by phpmailer
  • Repository
  • 871 Watchers
  • 11461 Stars
  • 6,596,099 Installations
  • PHP
  • 616 Dependents
  • 19 Suggesters
  • 6325 Forks
  • 24 Open issues
  • 47 Versions
  • 9 % Grown

The README.md

SWUbanner, (*1)

PHPMailer, (*2)

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

Test status codecov.io Latest Stable Version Total Downloads License API Docs OpenSSF Scorecard, (*3)

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 SMTPS and SMTP+STARTTLS transports
  • Validates email addresses automatically
  • Protects against header injection attacks
  • Error messages in over 50 languages!
  • DKIM and S/MIME signing support
  • Compatible with PHP 5.5 and later, including PHP 8.2
  • Namespaced to prevent name clashes
  • Much more!

Why you might need it

Many PHP developers need to send email from their code. The only PHP function that supports this directly is mail(). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments., (*4)

Formatting email correctly is surprisingly difficult. There are myriad overlapping (and conflicting) standards, 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, if not unsafe!, (*5)

The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP client allows email sending on all platforms without needing a local mail server. Be aware though, that the mail() function should be avoided when possible; it's both faster and safer to use SMTP to localhost., (*6)

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 , Laminas/Mail, ZetaComponents, etc., (*7)

License

This software is distributed under the LGPL 2.1 license, along with the GPL Cooperation Commitment. Please read LICENSE for information on the software availability and distribution., (*8)

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:, (*9)

"phpmailer/phpmailer": "^6.9.2"

or run, (*10)

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., (*11)

If you want to use XOAUTH2 authentication, you will also need to add a dependency on the league/oauth2-client and appropriate service adapters package in your composer.json, or take a look at by @decomplexity's SendOauth2 wrapper, especially if you're using Microsoft services., (*12)

Alternatively, if you're not using Composer, you can download PHPMailer as a zip file, (note that docs and examples are not included in the zip file), then 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:, (*13)

<?php
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. Even if you're not using exceptions, you do still need to load the Exception class as it is used internally., (*14)

Legacy versions

PHPMailer 5.2 (which is compatible with PHP 5.0 โ€” 7.0) is no longer supported, even for security updates. You will find the latest version of 5.2 in the 5.2-stable branch. If you're using PHP 5.5 or later (which you should be), switch to the 6.x releases., (*15)

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., (*16)

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 (very unlikely!), 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!, (*17)

A Simple Example

<?php
//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\SMTP;
use PHPMailer\PHPMailer\Exception;

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

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'smtp.example.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'user@example.com';                     //SMTP username
    $mail->Password   = 'secret';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     //Add a recipient
    $mail->addAddress('ellen@example.com');               //Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

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

    //Content
    $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';

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

You'll find plenty to play with in the examples folder, which covers many common scenarios including sending through Gmail, building contact forms, sending to mailing lists, and more., (*18)

If you are re-using the instance (e.g. when sending to a mailing list), you may need to clear the recipient list to avoid sending duplicate messages. See the mailing list example for further guidance., (*19)

That's it. You should now be ready to use PHPMailer!, (*20)

Localization

PHPMailer defaults to English, but in the language folder, you'll find many 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:, (*21)

//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, run the Language/TranslationCompletenessTest.php script in the tests folder and it will show any missing translations., (*22)

Documentation

Start reading at the GitHub wiki. If you're having trouble, head for the troubleshooting guide as it's frequently updated., (*23)

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., (*24)

To reduce PHPMailer's deployed code footprint, examples are not 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., (*25)

Complete generated API documentation is available online., (*26)

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

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., (*28)

Tests

PHPMailer tests use PHPUnit 9, with a polyfill to let 9-style tests run on older PHPUnit and PHP versions., (*29)

Test status, (*30)

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

Security

Please disclose any vulnerabilities found responsibly โ€“ report security issues to the maintainers privately., (*32)

See SECURITY and PHPMailer's security advisories on GitHub., (*33)

Contributing

Please submit bug reports, suggestions, and pull requests to the GitHub issue tracker., (*34)

We're particularly interested in fixing edge cases, expanding test coverage, and updating translations., (*35)

If you found a mistake in the docs, or want to add something, go ahead and amend the wiki โ€“ anyone can edit it., (*36)

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:, (*37)

git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git

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

Sponsorship

Development time and resources for PHPMailer are provided by Smartmessages.net, the world's only privacy-first email marketing system., (*39)

Smartmessages.net privacy-first email marketing logo, (*40)

Donations are very welcome, whether in beer ๐Ÿบ, T-shirts ๐Ÿ‘•, or cold, hard cash ๐Ÿ’ฐ. Sponsorship through GitHub is a simple and convenient way to say "thank you" to PHPMailer's maintainers and contributors โ€“ just click the "Sponsor" button on the project page. If your company uses PHPMailer, consider taking part in Tidelift's enterprise support programme., (*41)

PHPMailer For Enterprise

Available as part of the Tidelift Subscription., (*42)

The maintainers of PHPMailer and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open-source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more., (*43)

Changelog

See changelog., (*44)

History

  • 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 GitHub Actions.
  • 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.

The Versions

27/06 2018

dev-master

9999999-dev

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • ext-ctype *
  • php >=5.5.0
  • ext-filter *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

27/03 2018

v6.0.5

6.0.5.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *
  • ext-filter *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

27/03 2018

v6.0.4

6.0.4.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *
  • ext-filter *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

05/01 2018

v6.0.3

6.0.3.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *
  • ext-filter *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

30/11 2017

v6.0.2

6.0.2.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

14/09 2017

v6.0.1

6.0.1.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

28/08 2017

6.0.x-dev

6.0.9999999.9999999-dev

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

28/08 2017

v6.0.0

6.0.0.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

11/08 2017

dev-6.0-ical

dev-6.0-ical

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0
  • ext-ctype *

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

28/02 2017

v6.0.0rc5

6.0.0.0-RC5

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

09/01 2017

v6.0.0rc4

6.0.0.0-RC4

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

09/01 2017

v5.2.22

5.2.22.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

28/12 2016

v5.2.21

5.2.21.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

28/12 2016

v5.2.20

5.2.20.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

26/12 2016

v5.2.19

5.2.19.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

24/12 2016

v5.2.18

5.2.18.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

09/12 2016

v6.0.0rc3

6.0.0.0-RC3

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

09/12 2016

v5.2.17

5.2.17.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

06/06 2016

v5.2.16

5.2.16.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

11/05 2016

v6.0.0rc2

6.0.0.0-RC2

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

10/05 2016

v5.2.15

5.2.15.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

01/05 2016

v6.0.0rc1

6.0.0.0-RC1

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

19/04 2016

dev-xoauth

dev-xoauth

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.5.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

23/11 2015

dev-revert-565-back-compat

dev-revert-565-back-compat

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

01/11 2015

v5.2.14

5.2.14.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

14/09 2015

v5.2.13

5.2.13.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

02/09 2015

v5.2.12

5.2.12.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

31/08 2015

v5.2.11

5.2.11.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

07/05 2015

dev-travis

dev-travis

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

04/05 2015

v5.2.10

5.2.10.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

29/04 2015

dev-autotls

dev-autotls

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

17/04 2015

dev-longlines

dev-longlines

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

20/03 2015

dev-mimesign

dev-mimesign

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

26/09 2014

v5.2.9

5.2.9.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

14/05 2014

v5.2.8

5.2.8.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

12/09 2013

dev-smtp-refactor

dev-smtp-refactor

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

12/09 2013

v5.2.7

5.2.7.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

11/04 2013

v5.2.6

5.2.6.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

07/04 2013

v5.2.5

5.2.5.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

05/04 2013

dev-qmail

dev-qmail

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

21/02 2013

v5.2.4

5.2.4.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle

04/12 2012

v5.2.2

5.2.2.0

PHPMailer is a full-featured email creation and transfer class for PHP

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.0.0

 

The Development Requires

by Andy Prevost
by Jim Jagielski
by Brent R. Matzelle