Prestashop logo, Visit home page

Troubleshoot : Mails


Problem with mail() function in PHP

The mail() function requires the use of its fifth parameter to force the mail sender (FROM).

Typically, the sender is defined by the headers in the fourth parameter:

$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]\\r\\n";

mail($to, $subject, $txt, $headers);

The mail() function then calls the sendmail system tool. On our infrastructure, sendmail does not seem to interpret the From header and attempts to send mail with the address root@[environmentdomain].localdomain.

We can force sendmail to use the desired sender by setting the fifth parameter of the mail function to this value:

$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]\\r\\n";

mail($to, $subject, $txt, $headers, '[email protected]');


Problem with TLS when configuring custom SMTP server

You can switch from TLS to SSL.

On older versions of PrestaShop, the TLS version required by SwiftMailer does not seem to match the one defined in the environment.

If the SMTP server is Gmail for example, you can switch from TLS with port 587 to SSL with port 465.


Email Recommendations

Favor the use of a dedicated third-party email solution.

If you need to send emails directly from your host, it is recommended to use a tool such as Swift Mailer or Symfony Mailer. PrestaShop uses Swift Mailer. These tools do not depend on the mail() function in PHP but use sendmail directly.

It is highly recommended to use a dedicated third-party email solution like mailgun, mailjet, sendinblue, MailChimp, etc.


Was the article helpful?