In some servers the PHP mail function() is not available. This function is increasingly common that is disabled on servers, as a security measure. Normally it is deactivated by protection against SPAM, mail spoofing and proxy mail server. In case any of the websites hosted is violated by a malicious user, the aforementioned risks are avoided.
The PHPMailer library allows us, among other features, to establish an SMTP connection with a mail server. This SMTP server will be the one who actually sends our email.
The official website of the project on GitHub contains the documentation with the installation and configuration options. Link to Github: https://github.com/PHPMailer/PHPMailer
We will need to have an email account created and the connection data. For this example we will need: The outgoing mail server (SMTP Server), username and password.
It is the easiest and fastest option for users who already use composer in their project. Add to file composer.json:
composer require phpmailer/phpmailer
There is a complete configuration example on the Github page.
1.- Download the library of https://github.com/PHPMailer/PHPMailer, click the green button of “Clone or download” and “Download ZIP”
2.- Unzip the downloaded file “PHPMailer-master.zip” and rename the directory PHPMailer-master por PHPMailer
3.- Copy the PHPMailer directory into our project. To verify that the routes are correct, it should exist from the root of our project: /PHPMailer/src/PHPMailer.php