(This article has an advanced technical level, written for people with PhpMailer experience.)
PHPMailer 5.1 in PrestaShop 1.4
Trying to integrate PHPMailer in Prestashop and use it instead of SWIFT Mailer 3 (which is the default mailer script included with Prestashop 1.4), I spent hours to no avail and was getting the Could not instantiate mail function error.
The mail() function by itself was working correctly before and after loading Prestashop and every passed argument seemed to be correct. I did get the “Bad parameters to mail() function, mail not sent” error for mail() too.
Debugging and Abracadabra!
I’ve done lots of debugging and found in my case that the following functions were causing the error, when passing the $Subject parameter to mail():
To solve the “Could not instantiate mail function” error in PHPMailer, I removed the above 2 functions from the mail() function arguments.
Just be careful to remove these functions correctly from all places in your class.phpmailer.php.
I recommend using the PHP function
because it encodes your stuff correctly for the headers in emails.
To be more clear,
1- open the PHPMAILER class file (class.phpmailer.php)
protected function MailSend($header, $body)
function and in its body,
3- In every call to mail(),
@mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
@mail($val, mb_encode_mimeheader($this->Subject,$this->CharSet, 'B', ''), $body, $header, $params);
This way you are sure to correctly encode your subjet.
Remember to set the correct Charset for your PHPMAILER instance. That is, when calling PHPMailer, just after:
$mail->CharSet = 'UTF-8';
(or any other charset you need).
This solved my “Could not instantiate mail() function in PHPMailer issue. I hope it helps you out if you got this issue too.
I’ll write more about PHPMailer and PrestaShop later,
In my next post, learn how to correctly include inline images in PHPMailer email to display in GMAIL, YAHOO, Mac Mail app and other email clients correctly as inline images.