Moodle Error: Could not instantiate mail function

If you are here it is because you probably set up your moodle account and when your users tried to register, they could not login because their account was still on hold.  Also, they probably received this error and had little clue why this blocked them.

Well, this shortcoming or bug is probably a result of the restrictions placed on your space by your hosting company, for example.  At least it has been my case with GoDaddy.  Don’t get me wrong, I think overall they are a good value.  Anyway, on to the fix.

Open your class.phpmailer.php file under your moodle/lib/phpmailer folder. 

Here go to line 109 and change

     * Method to send mail: (“mail”, “sendmail”, or “smtp”).
     * @var string — Changed from mail to sendmail
    var $Mailer            = “mail”;


    var $Mailer            = “sendmail”;
Then go to line 269 and change

     * Sets Mailer to send message using PHP mail() function.
     * @return void — changed mail to sendmail
    function IsMail() {
        $this->Mailer = “mail”;

        $this->Mailer = “sendmail”;

Hopefully this should bypass using the mail() function completely.

It worked for me so I hope it works for you.


Filed under Computer - Technical

22 responses to “Moodle Error: Could not instantiate mail function

  1. Tyler

    thank you very much, i searched it solution for 3 hours and nothing was worked.
    But your method is worked, now it is ok perfectly. thanks again 🙂

  2. Dennis H

    The changes fixed the problem. However, another problem resulted–
    Fatal error: Call to undefined function: textlib_get_instance() in …/lib/phpmailer/class.phpmailer.php on line 1194.

    Moodle version 1.5.4
    PHP version 4.1.2
    Path to sendmail …/usr/sbin/sendmail -t -i
    (I have no idea what switches -t -i are for)

    Updating to current versions of Moodle and PHP might fix it, but unfortunately is not an option with the inexpensive paid hosting company I have. Any help is appreciated!

  3. Not sure what to make of it. From what I can gather, the textlib_get_instance() is calling the encode_mimeheader function found in the textlib.class.php file. This is trying to encode the values for that go in the message header to utf-8.

    The sendmail -t means, (Recipients are gathered from both the command line and the message header, and the message is delivered), the ‘-i’ means interactively

    Is there anything odd with the headers that you are sending? Recipients (i.e. e-mail addresses, names), subject, etc…

    I did find the not equal to operator to be a little odd, “!==”. I usually write “!=” Maybe the “!==” version of the not-equal-to operator is not recognized by your php version? Not sure.

    Are you receiving this error after a user creates his/her account?

  4. Alex

    tKS A lOT FROM bRAZIL !!

  5. rohith

    Its not working for me…i can send mail to gmail now..But for other id’s its telling that mail is sent. But not receiving in inbox

    • Could it be that the moodle generated messages are being treated like spam by other e-mail providers? Check your spam folders. I’ve experienced moodle account messages going to spam with yahoo. If the problem is something different, write back.

  6. Rohith

    No i have checked it..No mails in spam too..In gmail the mail is coming to spam in some time…Still i cant get the mails..If i didnt change the two lines you have mentioned, it will give the error like ” mail function could not initiated”
    ..Thanks for ur reply tooo


  7. Rohith

    The same thing is happens while we use any mailing function in moodle, forgot password, forum etc..So if i change these lines its telling that the mail is sent. But nothing in my inbox. Once i didnt change these lines then error: could not initiate the mail function

  8. muchas gracias por la ayuda.
    Tambíen estaba en Godaddy y me traia de cabeza el tema del envío de los mails.

  9. Thank You very much, your solution works for me!

  10. I did not select phpmailer on installation but php mail function what do i need to change?
    thanks I am working on a local intranet and all the mail setups are set

  11. Joey O.

    Thanks a lot!…. This one really works!!!

  12. SgGal

    Thankz… It works for me too.. =) Awesome!!

  13. i have some problem with u…
    this post help me to solve it…
    thx 😀

  14. Cylon

    This solved my problem (using goddady hosting). Thank you very much.

  15. Mine is different. It may be a newer version.

    Mine Says:
    public $Mailer = ‘mail’;

    instead of :
    var $Mailer = “mail”;

    • legramajo

      I did not change
      public $Mailer = ‘mail’; to var $Mailer = “mail”;
      instead I changed
      public $Mailer = ‘mail’; to public $Mailer = ‘sendmail’;
      and it worked, I am using goddady hosting too.

  16. ado

    Thanks a lot!…. This one really works!!!
    Thankz… It works for me too.. =) Awesome!!
    Thank You very much, your solution works for me!
    You the best …

  17. on my system email is working as i tried to reset password where i received in email notification (so smtp server is connected properly), but not receiving notification of quiz completion now I have enabled everywhere mod/quiz:emailconfirmsubmission and mod/quiz:emailnotifysubmission ,I don’t know what is wrong in this case ??

  18. Thanks, yours solve my xml prolog exception

  19. thank you very much,
    It was very helpfull …
    🙂 🙂 🙂

Comment on this

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s