Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

Difference between PHP MAIL and PHP MAILER

PHP Mail and PHP Mailer are two very useful tools for sending e-mails from web applications developed in PHP.

PHP Mail

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:

  1. A web server that supports PHP.
  2. An e-mail account from which e-mails will be sent.
  3. Basic knowledge of PHP.

To send an email using PHP Mail, follow these steps:

  1. Open a PHP file in your favorite text editor.
  2. Add the following line of code to the beginning of the file to set the email headers:
$headers = 'From: email_account_name@domain.com' . "\r\n" .
    'Reply-To: email_account_name@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
  1. 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.

  2. Add the following code to set the subject and body of the email:

$subject = 'Email subject';
$message = 'Email body';
  1. Replace "Email Subject " and "Email Body " with the actual subject and body of the email you wish to send.
  2. Add the following code to send the email:
mail('recipient@domain.com', $subject, $message, $headers);
  1. Replace "recipient@domain.com" with the recipient's e-mail address.

PHP Mailer

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:

  1. A web server that supports PHP
  2. An email account from which the emails will be sent.
  3. Basic knowledge of PHP

We have a manual on how to use PHP Mailer:

Conclusion

PHP MAIL

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.

PHP MAILER

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.