Prestashop owners prefer mail() over SMTP to send emails, because it’s so easy to use.
But, this can sometimes conflict with the server security settings and lead to errors.
If my Prestashop emails don’t work, how do I receive order confirmation emails or contact form emails?
That’s a common query we often resolve as part of our Technical Support Service for web hosting companies.
Today, let’s see the top 2 reasons for this error and how we fix it.
Prestashop emails not working – Top 2 reasons and solutions
Prestashop email errors can occur mainly due to the security restrictions in the server.
1. Disabled PHP mail() function
PHP mail() is an inherently vulnerable function. Hackers can exploit it and send spam.
To prevent this, some hosts may disable this mail() feature.
How we fix?
Our Support Engineers confirm whether the mail() function is disabled or not using a phpinfo page(<? phpinfo(); ?) in the website.
If this function is disabled, it will display under disable_functions list.
We then suggest the option to use SMTP function to send emails.
You can use the following SMTP settings in your Prestashop email configuration.
Mail domain name : Your store name. SMTP server : Your SMTP server. SMTP user : Your complete email account. SMTP password : Your email account password. Encryption : Either SSL or TLS encryption. Port : SMTP server port.
2. Security restrictions in the server
We see email providers use a security feature called SPF(Sender Policy Framework) to check the email authenticity of the sender.
It decides the servers that can send emails on behalf of a domain.
When emails don’t originate from the servers mentioned in the SPF record of the domain, mail server assumes it as fraud and rejects them.
As per Prestashop algorithm, when client puts his contact email address, say test@gmail.com, the system automatically assigns this email address as the FROM address of the message.
Consequently, the receiver end sees an email claiming to be FROM gmail.com, which is actually from a completely different server. Hence, it fails the SPF check process and mail bounces with the above error.
How we fix?
The quick solution is to modify the Prestashop Swift Mailer module.
We need to modify 3 files here. But before that, we always take a backup of the files.
1) Open the file /tools/swift/Swift/Message.php and change the FROM field to be an email associated with your domain.
Change:
$this->setFrom("");
To
$this->setFrom("yourmailid@yourdomainname");
2) Open /tools/swift/Swift.php and add client’s email given in the contact form as Reply-to email by modifying the below line.
Change:
if (!($has_reply_to = $message->getReplyTo())) $message->setReplyTo($from);
To:
if (!($has_reply_to = $message->getReplyTo())) $message->setReplyTo($from); if (!$has_reply_to[0]) $message->setReplyTo($from->getAddress());
3) Open /tools/swift/Swift/Plugin/MailSend.php to disable additional parameters in the message.
Change:
$headers = $headers->build();
To
$headers = $headers->build(); $params = "";
That’s it. Your Prestashop site should now be able to send emails.
Conclusion
Prestashop email errors can occur due to security restrictions in the server. “Sending failed using mail() as PHP’s default mail() function returned boolean FALSE” is one such error. Today, we’ve discussed the top 2 reasons for this error and how our Support Engineers fix them.
Nice explanation. I think most of shop owners use some custom SMTP servers for sending emails.
If you self host from your residential ISP and they block port 25, does that make sendmail useless? I.E. can you even use it and if you change ports, won’t you never receive email? I tried SMPT through gmail and I get nothing but authentication errors, it can never make the login and pw work.
Hi,
Our Experts can help you with the issue, we’ll be happy to talk to you on chat (click on the icon at right-bottom).