ManyPHPdevelopersneedtosendemailfromtheircode.TheonlyPHPfunctionthatsupportsthisdirectlyis[`mail()`](https://www.php.net/manual/en/function.mail.php). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments.
ThePHP`mail()`functionusuallysendsviaalocalmailserver,typicallyfrontedbya`sendmail`binaryonLinux,BSD,andmacOSplatforms,however,Windowsusuallydoesn'tincludealocalmailserver;PHPMailer'sintegratedSMTPclientallowsemailsendingonallplatformswithoutneedingalocalmailserver.Beawarethough,thatthe`mail()`functionshouldbeavoidedwhenpossible;it'sbothfasterand[safer](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html) to use SMTP to localhost.
,[Laminas/Mail](https://docs.laminas.dev/laminas-mail/), [ZetaComponents](https://github.com/zetacomponents/Mail) etc.
##License
Thissoftwareisdistributedunderthe[LGPL2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license, along with the [GPL Cooperation Commitment](https://gplcc.github.io/gplcc/). Please read [LICENSE](https://github.com/PHPMailer/PHPMailer/blob/master/LICENSE) for information on the software availability and distribution.
##Installation&loading
PHPMailerisavailableon[Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file:
can[downloadPHPMailerasazipfile](https://github.com/PHPMailer/PHPMailer/archive/master.zip), (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:
PHPMailer5.2(whichiscompatiblewithPHP5.0—7.0)isnolongersupported,evenforsecurityupdates.Youwillfindthelatestversionof5.2inthe[5.2-stablebranch](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable). If you're using PHP 5.5 or later (which you should be), switch to the 6.x releases.
###Upgradingfrom5.2
Thebiggestchangesarethatsourcefilesarenowinthe`src/`folder,andPHPMailernowdeclaresthenamespace`PHPMailer\PHPMailer`.Thishasseveralimportanteffects–[readtheupgradeguide](https://github.com/PHPMailer/PHPMailer/tree/master/UPGRADING.md) for more details.
###Minimalinstallation
WhileinstallingtheentirepackagemanuallyorwithComposerissimple,convenient,andreliable,youmaywanttoincludeonlyvitalfilesinyourproject.Attheveryleastyouwillneed[src/PHPMailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/SMTP.php), and if you're using POP-before SMTP (*very* unlikely!), you'll need [src/POP3.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/POP3.php). You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/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](https://github.com/PHPMailer/PHPMailer/tree/master/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!
##ASimpleExample
```php
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
usePHPMailer\PHPMailer\PHPMailer;
usePHPMailer\PHPMailer\SMTP;
usePHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require'vendor/autoload.php';
//Create an instance; passing `true` enables exceptions
echo"Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
```
You'llfindplentytoplaywithinthe[examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder, which covers many common scenarios including sending through gmail, building contact forms, sending to mailing lists, and more.
Ifyouarere-usingtheinstance(e.g.whensendingtoamailinglist),youmayneedtocleartherecipientlisttoavoidsendingduplicatemessages.See[themailinglistexample](https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps) for further guidance.
That'sit.YoushouldnowbereadytousePHPMailer!
##Localization
PHPMailerdefaultstoEnglish,butinthe[language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find many translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/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:
Wewelcomecorrectionsandnewlanguages–ifyou'relookingforcorrections,runthe[PHPMailerLangTest.php](https://github.com/PHPMailer/PHPMailer/tree/master/test/PHPMailerLangTest.php) script in the tests folder and it will show any missing translations.
##Documentation
Startreadingatthe[GitHubwiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, head for [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) as it's frequently updated.
ExamplesofhowtousePHPMailerforcommonscenarioscanbefoundinthe[examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder. If you're looking for a good starting point, we recommend you start with [the Gmail example](https://github.com/PHPMailer/PHPMailer/tree/master/examples/gmail.phps).
ToreducePHPMailer'sdeployedcodefootprint,examplesarenotincludedifyouloadPHPMailerviaComposerorvia[GitHub'szipfiledownload](https://github.com/PHPMailer/PHPMailer/archive/master.zip), so you'll need to either clone the git repository or use the above links to get to the examples directly.
YoucangeneratecompleteAPI-leveldocumentationbyrunning`phpdoc`inthetop-levelfolder,anddocumentationwillappearinthe`docs`folder,thoughyou'llneedtohave[PHPDocumentor](http://www.phpdoc.org) installed. You may find [the unit tests](https://github.com/PHPMailer/PHPMailer/blob/master/test/PHPMailerTest.php) a good reference for how to do various operations such as encryption.
Ifthedocumentationdoesn'tcoverwhatyouneed,searchthe[manyquestionsonStackOverflow](http://stackoverflow.com/questions/tagged/phpmailer), and before you ask a question about "SMTP Error: Could not connect to SMTP host.", [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting).
##Tests
[PHPMailertests](https://github.com/PHPMailer/PHPMailer/tree/master/test/) use PHPUnit 9, with [a polyfill](https://github.com/Yoast/PHPUnit-Polyfills) to let 9-style tests run on older PHPUnit and PHP versions.
See[SECURITY](https://github.com/PHPMailer/PHPMailer/tree/master/SECURITY.md) and [PHPMailer's security advisories on GitHub](https://github.com/PHPMailer/PHPMailer/security).
DevelopmenttimeandresourcesforPHPMailerareprovidedby[Smartmessages.net](https://info.smartmessages.net/), the world's only privacy-first email marketing system.
Donationsareverywelcome,whetherinbeer🍺,T-shirts👕,orcold,hardcash💰.SponsorshipthroughGitHubisasimpleandconvenientwaytosay"thank you"toPHPMailer'smaintainersandcontributors–justclickthe"Sponsor"button[ontheprojectpage](https://github.com/PHPMailer/PHPMailer). If your company uses PHPMailer, consider taking part in Tidelift's enterprise support programme.