PHP Mail and PHP Mailer are two very useful tools for sending e-mails from web applications developed in PHP.
PHP Mail is a PHP function that allows you to send emails from a web application. To use PHP Mail, you will need the following:
To send an email using PHP Mail, follow these steps:
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Replace email_account_name with the name of the email account you will use to send the email and "domain.com " with the corresponding email domain.
Add the following code to set the subject and body of the email:
$subject = 'Email subject';
$message = 'Email body';
mail('[email protected]', $subject, $message, $headers);
PHP Mailer is a PHP library that simplifies the process of sending emails from a web application. To use PHP Mailer, you will need the following:
We have a manual on how to use PHP Mailer:
The PHP mail() function, although easier to configure, does not support the SMTP protocol.
This function is more and more often disabled on servers as a security measure. It is usually disabled for protection against SPAM, mail spoofing and proxy mail server.
In some of our services such as Hosting and servers with SWPanel this function is disabled by default.
The PHP Mailer function is much more secure and supports the SMTP protocol.
This SMTP server will be the one who will actually send our email, thus having the DKIM signature and SPF record. We can thus validate the legitimacy of the email.
It also allows to send more complex e-mails, allowing to attach images and files, something that the mail function () does not allow.
In summary, PHP Mail and PHP Mailer are two very useful tools for sending emails from web applications developed in PHP.