[SOLVED] Could not instantiate mail function in PHPMailer

By | 20/05/2011

(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.

mail() function

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

http://php.net/manual/en/function.mb-encode-mimeheader.php

because it encodes your stuff correctly for the headers in emails.

To be more clear,

1- open the PHPMAILER class file (class.phpmailer.php)

2- Locate:

function and in its body,

3- In every call to mail(),

replace this:

by this:

 

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:

add:

(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.

Evenmore:

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.

Category: Ramblings Tags: , ,

About Gi

I love new technologies and try to use them in my everyday life. Since many years ago, I write about these technologies, and provide solutions to the issues people might get using the new world. I tested and experienced the solutions I provide. I love helping people, and that's why my publications have been free until now.

5 thoughts on “[SOLVED] Could not instantiate mail function in PHPMailer

  1. Gopal

    hello,
    $mail->CharSet = ‘UTF-8’; is important for the different server.

    Regards
    GOpal Rathod

    Reply
  2. Marquee

    Gopal, just want to clarify where could i find the File for the line of code below?

    $mail=new PHPMailer(true);

    so that i could add this line as you mention

    $mail->CharSet = ‘UTF-8’;

    I’m using joomla 2.5.8

    Thank you in advance and more power..

    Reply
    1. simon shields

      u add that after $mail = new PHPMailer() ;

      Reply
  3. simon shields

    I discovered that if I had % character in the message the mail wouldn’t send using mail or phpmailer $mail->Send(). I would get the same error message “could not instantiate….mail..”. When I removed the % via $content = str_replace(“%”,””,$content); the message sent without a problem. I did try all the suggested remedies, nothing worked until I removed the ‘%’ character. Very strange obviously the mail() function must be interpreting the % character and it was causing it problems. The % character was surrounded by whitespace e.g. “100 % certain” . I’m am going to investigate further and see if i can resolve it. I think it must be a operating system issue but i’m not certain about this.

    Reply
  4. ronak`

    I am facing same issue but cant resolving this can you please help me to solve this ?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge