README.md (mrbs-1.9.4) | : | README.md (mrbs-1.10.0) | ||
---|---|---|---|---|
 |  | |||
# PHPMailer – A full-featured email creation and transfer class for PHP | # PHPMailer – A full-featured email creation and transfer class for PHP | |||
[](https://github.com/PHPMailer/PHPMailer/actions) [](https://github.com/PHPMailer/PHPMailer/actions) | |||
ps://poser.pugx.org/phpmailer/phpmailer/v/stable.svg)](https://packagist.org/pac | [ [](https://codecov.io/gh/PHPMailer/PHPMailer) | |||
phpmailer/downloads)](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist | g)](https://packagist.org/packages/phpmailer/phpmailer) | |||
.org/packages/phpmailer/phpmailer) [](https | |||
mailer/workflows/Docs/badge.svg)](https://phpmailer.github.io/PHPMailer/) | ://packagist.org/packages/phpmailer/phpmailer) | |||
[](https://pac | ||||
kagist.org/packages/phpmailer/phpmailer) | ||||
[](h | ||||
ttps://phpmailer.github.io/PHPMailer/) | ||||
## Features | ## Features | |||
- Probably the world's most popular code for sending email from PHP! | - Probably the world's most popular code for sending email from PHP! | |||
- Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joo mla! and many more | - Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joo mla! and many more | |||
- Integrated SMTP support – send without a local mail server | - Integrated SMTP support – send without a local mail server | |||
- Send emails with multiple To, CC, BCC and Reply-to addresses | - Send emails with multiple To, CC, BCC and Reply-to addresses | |||
- Multipart/alternative emails for mail clients that do not read HTML email | - Multipart/alternative emails for mail clients that do not read HTML email | |||
- Add attachments, including inline | - Add attachments, including inline | |||
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encod ings | - Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encod ings | |||
- SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over S MTPS and SMTP+STARTTLS transports | - SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over S MTPS and SMTP+STARTTLS transports | |||
- Validates email addresses automatically | - Validates email addresses automatically | |||
- Protects against header injection attacks | - Protects against header injection attacks | |||
- Error messages in over 50 languages! | - Error messages in over 50 languages! | |||
- DKIM and S/MIME signing support | - DKIM and S/MIME signing support | |||
- Compatible with PHP 5.5 and later, including PHP 8.0 | - Compatible with PHP 5.5 and later, including PHP 8.1 | |||
- Namespaced to prevent name clashes | - Namespaced to prevent name clashes | |||
- Much more! | - Much more! | |||
## Why you might need it | ## Why you might need it | |||
Many PHP developers need to send email from their code. The only PHP function th at supports this directly is [`mail()`](https://www.php.net/manual/en/function.m ail.php). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments. | Many PHP developers need to send email from their code. The only PHP function th at supports this directly is [`mail()`](https://www.php.net/manual/en/function.m ail.php). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments. | |||
Formatting email correctly is surprisingly difficult. There are myriad overlappi ng (and conflicting) standards, requiring tight adherence to horribly complicate d formatting and encoding rules – the vast majority of code that you'll find onl ine that uses the `mail()` function directly is just plain wrong, if not unsafe! | Formatting email correctly is surprisingly difficult. There are myriad overlappi ng (and conflicting) standards, requiring tight adherence to horribly complicate d formatting and encoding rules – the vast majority of code that you'll find onl ine that uses the `mail()` function directly is just plain wrong, if not unsafe! | |||
The PHP `mail()` function usually sends via a local mail server, typically front ed by a `sendmail` binary on Linux, BSD, and macOS platforms, however, Windows u sually doesn't include a local mail server; PHPMailer's integrated SMTP client a llows email sending on all platforms without needing a local mail server. Be awa re though, that the `mail()` function should be avoided when possible; it's both faster and [safer](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun -And-RCE.html) to use SMTP to localhost. | The PHP `mail()` function usually sends via a local mail server, typically front ed by a `sendmail` binary on Linux, BSD, and macOS platforms, however, Windows u sually doesn't include a local mail server; PHPMailer's integrated SMTP client a llows email sending on all platforms without needing a local mail server. Be awa re though, that the `mail()` function should be avoided when possible; it's both faster and [safer](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun -And-RCE.html) to use SMTP to localhost. | |||
skipping to change at line 42 | skipping to change at line 47 | |||
you should look at before rolling your own. Try [SwiftMailer](https://swiftmaile r.symfony.com/) | you should look at before rolling your own. Try [SwiftMailer](https://swiftmaile r.symfony.com/) | |||
, [Laminas/Mail](https://docs.laminas.dev/laminas-mail/), [ZetaComponents](https ://github.com/zetacomponents/Mail) etc. | , [Laminas/Mail](https://docs.laminas.dev/laminas-mail/), [ZetaComponents](https ://github.com/zetacomponents/Mail) etc. | |||
## License | ## License | |||
This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lg pl-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 distributi on. | This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lg pl-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 distributi on. | |||
## Installation & loading | ## Installation & loading | |||
PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/p hpmailer) (using semantic versioning), and installation via [Composer](https://g etcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file: | PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/p hpmailer) (using semantic versioning), and installation via [Composer](https://g etcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file: | |||
```json | ```json | |||
"phpmailer/phpmailer": "^6.2" | "phpmailer/phpmailer": "^6.5" | |||
``` | ``` | |||
or run | or run | |||
```sh | ```sh | |||
composer require phpmailer/phpmailer | 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. | Note that the `vendor` folder and the `vendor/autoload.php` script are generated by Composer; they are not part of PHPMailer. | |||
skipping to change at line 92 | skipping to change at line 97 | |||
<?php | <?php | |||
//Import PHPMailer classes into the global namespace | //Import PHPMailer classes into the global namespace | |||
//These must be at the top of your script, not inside a function | //These must be at the top of your script, not inside a function | |||
use PHPMailer\PHPMailer\PHPMailer; | use PHPMailer\PHPMailer\PHPMailer; | |||
use PHPMailer\PHPMailer\SMTP; | use PHPMailer\PHPMailer\SMTP; | |||
use PHPMailer\PHPMailer\Exception; | use PHPMailer\PHPMailer\Exception; | |||
//Load Composer's autoloader | //Load Composer's autoloader | |||
require 'vendor/autoload.php'; | require 'vendor/autoload.php'; | |||
//Instantiation and passing `true` enables exceptions | //Create an instance; passing `true` enables exceptions | |||
$mail = new PHPMailer(true); | $mail = new PHPMailer(true); | |||
try { | try { | |||
//Server settings | //Server settings | |||
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output | $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output | |||
$mail->isSMTP(); //Send using SMT P | $mail->isSMTP(); //Send using SMT P | |||
$mail->Host = 'smtp.example.com'; //Set the SMTP s erver to send through | $mail->Host = 'smtp.example.com'; //Set the SMTP s erver to send through | |||
$mail->SMTPAuth = true; //Enable SMTP au thentication | $mail->SMTPAuth = true; //Enable SMTP au thentication | |||
$mail->Username = 'user@example.com'; //SMTP username | $mail->Username = 'user@example.com'; //SMTP username | |||
$mail->Password = 'secret'; //SMTP password | $mail->Password = 'secret'; //SMTP password | |||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS enc | $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implici | |||
ryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged | t TLS encryption | |||
$mail->Port = 587; //TCP port to co | $mail->Port = 465; //TCP port to co | |||
nnect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above | nnect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` | |||
//Recipients | //Recipients | |||
$mail->setFrom('from@example.com', 'Mailer'); | $mail->setFrom('from@example.com', 'Mailer'); | |||
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient | $mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient | |||
$mail->addAddress('ellen@example.com'); //Name is optional | $mail->addAddress('ellen@example.com'); //Name is optional | |||
$mail->addReplyTo('info@example.com', 'Information'); | $mail->addReplyTo('info@example.com', 'Information'); | |||
$mail->addCC('cc@example.com'); | $mail->addCC('cc@example.com'); | |||
$mail->addBCC('bcc@example.com'); | $mail->addBCC('bcc@example.com'); | |||
//Attachments | //Attachments | |||
End of changes. 5 change blocks. | ||||
15 lines changed or deleted | 19 lines changed or added |