Warning - Could not instantiate mail function. Topic is solved
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Warning - Could not instantiate mail function.
I just uploaded my new Joomla 4 site, I did a test email from the Global Configuration Server using the default PHP setting, it sends a mail to me. My Contact form is linked to my Super Admin email, when I send a test email from my site I get this error:
Warning - Could not instantiate mail function.
I set up with both reCAPTCHA V2 and V3, no luck.
I changed from PHP to Sendmail, no luck. Also PHP, Sendmail & SMTP will successfully send a Test Mail to me, I just can't get the mail to come out of the Contact form when I try a test mail.
Note: I'm on Siteground, here's my site: https://www.consulting-japan.com/
I'm sure this is something simple, I'm completely frustrated as I I've checked everything I can think of.
Your support would be greatly appreciated...
John
Warning - Could not instantiate mail function.
I set up with both reCAPTCHA V2 and V3, no luck.
I changed from PHP to Sendmail, no luck. Also PHP, Sendmail & SMTP will successfully send a Test Mail to me, I just can't get the mail to come out of the Contact form when I try a test mail.
Note: I'm on Siteground, here's my site: https://www.consulting-japan.com/
I'm sure this is something simple, I'm completely frustrated as I I've checked everything I can think of.
Your support would be greatly appreciated...
John
- ceford
- Joomla! Hero
- Posts: 2290
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: Warning - Could not instantiate mail function.
I think you need a stack trace: in Global Configuration set Debug System to Yes and Error Reporting to Maximum. Then trigger the error and see what the stack trace has in it. Then set Debug System back to No.
The error message is in PHPMailer.php but it is not possible to see where it is triggered by reading the code.
The error message is in PHPMailer.php but it is not possible to see where it is triggered by reading the code.
- Webdongle
- Joomla! Master
- Posts: 43209
- Joined: Sat Apr 05, 2008 9:58 pm
Re: Warning - Could not instantiate mail function.
Most often it is using the wrong captcha keys
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
Is the contact form you tested from the Joomla core Contacts component or from a third party extension?
Toivo Talikka, Global Moderator
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function.
jd-morris wrote: ↑Thu May 26, 2022 1:38 pmI just uploaded my new Joomla 4 site, I did a test email from the Global Configuration Server using the default PHP setting, it sends a mail to me. My Contact form is linked to my Super Admin email, when I send a test email from my site I get this error:
Warning - Could not instantiate mail function.
I set up with both reCAPTCHA V2 and V3, no luck.
I changed from PHP to Sendmail, no luck. Also PHP, Sendmail & SMTP will successfully send a Test Mail to me, I just can't get the mail to come out of the Contact form when I try a test mail.
Note: I'm on Siteground, here's my site: https://www.consulting-japan.com/
I'm sure this is something simple, I'm completely frustrated as I I've checked everything I can think of.
Your support would be greatly appreciated...
John
Thank you, I set this, where is stack trace code?ceford wrote: ↑Thu May 26, 2022 2:09 pmI think you need a stack trace: in Global Configuration set Debug System to Yes and Error Reporting to Maximum. Then trigger the error and see what the stack trace has in it. Then set Debug System back to No.
The error message is in PHPMailer.php but it is not possible to see where it is triggered by reading the code.
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
- ceford
- Joomla! Hero
- Posts: 2290
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: Warning - Could not instantiate mail function.
It should be immediately following the Warning - Could not instantiate mail function message.jd-morris wrote: ↑Thu May 26, 2022 2:46 pmThank you, I set this, where is stack trace code?ceford wrote: ↑Thu May 26, 2022 2:09 pmI think you need a stack trace: in Global Configuration set Debug System to Yes and Error Reporting to Maximum. Then trigger the error and see what the stack trace has in it. Then set Debug System back to No.
The error message is in PHPMailer.php but it is not possible to see where it is triggered by reading the code.
Unless that is showing in a System message. A screenshot would be useful. And the System - Debug plugin needs to be enabled.
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function.
I enabled the Debug Plugin, set Error Reporting to Maximum, I received the same error messageceford wrote: ↑Thu May 26, 2022 3:23 pmIt should be immediately following the Warning - Could not instantiate mail function message.jd-morris wrote: ↑Thu May 26, 2022 2:46 pmThank you, I set this, where is stack trace code?ceford wrote: ↑Thu May 26, 2022 2:09 pmI think you need a stack trace: in Global Configuration set Debug System to Yes and Error Reporting to Maximum. Then trigger the error and see what the stack trace has in it. Then set Debug System back to No.
The error message is in PHPMailer.php but it is not possible to see where it is triggered by reading the code.
Unless that is showing in a System message. A screenshot would be useful. And the System - Debug plugin needs to be enabled.
You do not have the required permissions to view the files attached to this post.
- ceford
- Joomla! Hero
- Posts: 2290
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: Warning - Could not instantiate mail function.
Clutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:
I don't know if this will help - in the Global Configuration / Logging panel set Log Almost Everything to Yes. Then in Log Priorities delete All and select Debug. Save. Send your message and then look in administrator/logs/everything.php with a text editor. I see a 90 lines related to sending a test email. Afterwards, turn off logging.
Code: Select all
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
...
if (!$result) {
throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
}
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function.
I deleted my site, reloaded my old site with Akeeba, new DB...etc. I wanted to check my old mail settings and a few things, it was set up with PHP, and I tested it again, checked my reCAPTCHA.ceford wrote: ↑Thu May 26, 2022 5:17 pmClutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:
I don't know if this will help - in the Global Configuration / Logging panel set Log Almost Everything to Yes. Then in Log Priorities delete All and select Debug. Save. Send your message and then look in administrator/logs/everything.php with a text editor. I see a 90 lines related to sending a test email. Afterwards, turn off logging.Code: Select all
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params); ... if (!$result) { throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL); }
Then extracted my new site again, I did as you suggested above and still now error messages, other than Warning
Could not instantiate mail function.
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function.
Here's The everything.phpjd-morris wrote: ↑Thu May 26, 2022 5:57 pmI deleted my site, reloaded my old site with Akeeba, new DB...etc. I wanted to check my old mail settings and a few things, it was set up with PHP, and I tested it again, checked my reCAPTCHA.ceford wrote: ↑Thu May 26, 2022 5:17 pmClutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:
I don't know if this will help - in the Global Configuration / Logging panel set Log Almost Everything to Yes. Then in Log Priorities delete All and select Debug. Save. Send your message and then look in administrator/logs/everything.php with a text editor. I see a 90 lines related to sending a test email. Afterwards, turn off logging.Code: Select all
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params); ... if (!$result) { throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL); }
Then extracted my new site again, I did as you suggested above and still now error messages, other than Warning
Could not instantiate mail function.
#
#<?php die('Forbidden.'); ?>
#Date: 2022-05-26 17:50:47 UTC
#Software: Joomla! 4.1.4 Stable [ Kuamini ] 24-May-2022 16:00 GMT
#Fields: datetime priority clientip category message
2022-05-26T17:50:47+00:00 CRITICAL 133.202.83.176 error Uncaught Throwable of type Joomla\CMS\Router\Exception\RouteNotFoundException thrown with message "Page not found". Stack trace: #0 [ROOT]/libraries/src/Application/CMSApplication.php(1069): Joomla\CMS\Router\Router->parse(Object(Joomla\CMS\Uri\Uri), true)
#1 [ROOT]/libraries/src/Application/SiteApplication.php(820): Joomla\CMS\Application\CMSApplication->route()
#2 [ROOT]/libraries/src/Application/SiteApplication.php(228): Joomla\CMS\Application\SiteApplication->route()
#3 [ROOT]/libraries/src/Application/CMSApplication.php(278): Joomla\CMS\Application\SiteApplication->doExecute()
#4 [ROOT]/includes/app.php(63): Joomla\CMS\Application\CMSApplication->execute()
#5 [ROOT]/index.php(32): require_once('/home/customer/...')
#6 {main}
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Sending with mail()
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Sendmail path: /usr/sbin/sendmail -t -i
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Envelope sender:
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: To: "[email protected]" <[email protected]>
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Subject: Strategic Consulting Japan: Testing
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Headers: Date: Thu, 26 May 2022 17:51:14 +0000
From: Strategic Consulting Japan <[email protected]>
Reply-To: John <[email protected]>
Message-ID: <FCCr[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Result: false
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Could not instantiate mail function.
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Sending with mail()
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Sendmail path: /usr/sbin/sendmail -t -i
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Envelope sender:
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: To: "[email protected]" <[email protected]>
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Subject: Strategic Consulting Japan: Testing
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Headers: Date: Thu, 26 May 2022 17:51:14 +0000
From: Strategic Consulting Japan <[email protected]>
Reply-To: John <[email protected]>
Message-ID: <AL00[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Result: false
2022-05-26T17:51:14+00:00 ERROR 133.202.83.176 mail Error in Mail API: Could not instantiate mail function.
2022-05-26T17:51:14+00:00 WARNING 133.202.83.176 jerror Could not instantiate mail function.
2022-05-26T17:51:15+00:00 CRITICAL 133.202.83.176 error Uncaught Throwable of type Joomla\CMS\Router\Exception\RouteNotFoundException thrown with message "Page not found". Stack trace: #0 [ROOT]/libraries/src/Application/CMSApplication.php(1069): Joomla\CMS\Router\Router->parse(Object(Joomla\CMS\Uri\Uri), true)
#1 [ROOT]/libraries/src/Application/SiteApplication.php(820): Joomla\CMS\Application\CMSApplication->route()
#2 [ROOT]/libraries/src/Application/SiteApplication.php(228): Joomla\CMS\Application\SiteApplication->route()
#3 [ROOT]/libraries/src/Application/CMSApplication.php(278): Joomla\CMS\Application\SiteApplication->doExecute()
#4 [ROOT]/includes/app.php(63): Joomla\CMS\Application\CMSApplication->execute()
#5 [ROOT]/index.php(32): require_once('/home/customer/...')
#6 {main}
- ceford
- Joomla! Hero
- Posts: 2290
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: Warning - Could not instantiate mail function.
I don't use contact forms myself so I can't help any more just now. Can you be more specific about how to create the error? What do you do to show a contact form. What do site visitors do to trigger a message to be sent to you. Menu items or screen shots?
Anyone else able to help?
Anyone else able to help?
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function.
Yes, it's a single standard Joomla contact form. Joomla internally is working see attached. However once the form is filled out my a visitor it doesn't send, and I get the error, see attached.ceford wrote: ↑Thu May 26, 2022 8:01 pmI don't use contact forms myself so I can't help any more just now. Can you be more specific about how to create the error? What do you do to show a contact form. What do site visitors do to trigger a message to be sent to you. Menu items or screen shots?
Anyone else able to help?
I temporarily disabled my contact form as I've been up all night.
You do not have the required permissions to view the files attached to this post.
- Webdongle
- Joomla! Master
- Posts: 43209
- Joined: Sat Apr 05, 2008 9:58 pm
Re: Warning - Could not instantiate mail function.
Have you tried without the captcha?
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
This is possibly off-topic but related. Have just tested the com_contact contact form in two Joomla 4.1.4 test sites hosted in Wampserver, where test emails work all right with smtp.gmail.com.
The form was submitted, the form disappears but the page does not display an acknowledgement message like "Thank you for your email" in Joomla 3.10. No messages are sent or received, there are no error messages with 'Maximum' and Debug turn on either, no nothing.
I will test this function on a remote server and create an issue at https://issues.joomla.org
The form was submitted, the form disappears but the page does not display an acknowledgement message like "Thank you for your email" in Joomla 3.10. No messages are sent or received, there are no error messages with 'Maximum' and Debug turn on either, no nothing.
I will test this function on a remote server and create an issue at https://issues.joomla.org
Toivo Talikka, Global Moderator
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
The second test on a remote Joomla 4.1.4 site using PHP Mail worked all right. The Contact form sent the contact email and a copy to the sender and it also displays "Thank you for your email".
At least one more test required, using SMTP from the remote server. And that test went perfectly, too.
Will now investigate the Wampserver environment, starting from a clean installation of Joomla 4.1.4.
At least one more test required, using SMTP from the remote server. And that test went perfectly, too.
Will now investigate the Wampserver environment, starting from a clean installation of Joomla 4.1.4.
Toivo Talikka, Global Moderator
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
Installed a new Joomla 4.1.4 test site on Wampserver in Windows 10 and configured SMTP with smtp.gmail.com. The test email works and so does the Contact email, which also displays a thank you message:
Then changed the Mailer in Global Configuration of the test to PHP Mail. The section [mail function] of the php.ini file in the bin folder of Apache in the Wamp64 folder does not point to an SMTP server that could forward emails and therefore the instantiation of the mail function fails:
Test emails from Global Configuration of the OP's website work but a simple email sent from the Joomla contact form doesn't. The difference between those two use cases is that the test email from the Server tab of the Global Configuration is sent to the email address specified in the From Email field. The Contact email is possibly sent to a different mail domain, a domain that is not the same as the domain of the web server. Maybe the host does not allow that or maybe the host blocks attempts to connect to external mail servers.
Then changed the Mailer in Global Configuration of the test to PHP Mail. The section [mail function] of the php.ini file in the bin folder of Apache in the Wamp64 folder does not point to an SMTP server that could forward emails and therefore the instantiation of the mail function fails:
Test emails from Global Configuration of the OP's website work but a simple email sent from the Joomla contact form doesn't. The difference between those two use cases is that the test email from the Server tab of the Global Configuration is sent to the email address specified in the From Email field. The Contact email is possibly sent to a different mail domain, a domain that is not the same as the domain of the web server. Maybe the host does not allow that or maybe the host blocks attempts to connect to external mail servers.
You do not have the required permissions to view the files attached to this post.
Toivo Talikka, Global Moderator
- jd-morris
- Joomla! Apprentice
- Posts: 17
- Joined: Wed Apr 21, 2010 5:57 pm
- Location: Tokyo
- Contact:
Re: Warning - Could not instantiate mail function. [Solved]
After a long night, I finally resolved this, hopefully this helps others:
Siteground changed their mail system, I was on PHP which worked until launched my new site (likely a legacy thing). My Office 365 needed to be set up as SMTP was not enabled, this only took a few minutes.
Once I set this up with my Office 365 Enterprise account, I entered my credentials into the Joomla SMTP mail settings and finally all is working perfectly with my site!
Siteground changed their mail system, I was on PHP which worked until launched my new site (likely a legacy thing). My Office 365 needed to be set up as SMTP was not enabled, this only took a few minutes.
Once I set this up with my Office 365 Enterprise account, I entered my credentials into the Joomla SMTP mail settings and finally all is working perfectly with my site!
Last edited by jd-morris on Fri May 27, 2022 7:07 am, edited 1 time in total.
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
Good to hear, thank you for the update!
Toivo Talikka, Global Moderator
-
- Joomla! Enthusiast
- Posts: 131
- Joined: Wed Jul 29, 2009 3:33 pm
- Contact:
Re: Warning - Could not instantiate mail function.
OK, but does that mean you can't use the PHP option, when the PHP test email works just fine?
This doesn't make sense to me.
Is there additional settings that can be tested or perhaps another form software?
This doesn't make sense to me.
Is there additional settings that can be tested or perhaps another form software?
-
- Joomla! Enthusiast
- Posts: 131
- Joined: Wed Jul 29, 2009 3:33 pm
- Contact:
Re: Warning - Could not instantiate mail function.
Also, I just tried a 3rd party software form creator and it worked just fine.
I feel like there must be an issue with Joomla's contact form in Joomla 4.
I feel like there must be an issue with Joomla's contact form in Joomla 4.
-
- Joomla! Fledgling
- Posts: 2
- Joined: Sat Feb 04, 2023 1:35 am
Re: Warning - Could not instantiate mail function.
I think you are right. I have never seen so many posts around about this.
Has anyone actually asked Joomla about it?

- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
@yumasan and @Paul Stalli, read the test results from viewtopic.php?f=810&t=994062#p3661154?
Hosts can have restrictions in their network so that the selection of PHP Mail as Mailer allows the Test Mail to work because the test email is sent to the Sender address defined in Global Configuration of Joomla. Sending to email addresses outside the mail domain of the web server requires either Sendmail or SMTP.
Hosts can have restrictions in their network so that the selection of PHP Mail as Mailer allows the Test Mail to work because the test email is sent to the Sender address defined in Global Configuration of Joomla. Sending to email addresses outside the mail domain of the web server requires either Sendmail or SMTP.
Toivo Talikka, Global Moderator
-
- Joomla! Fledgling
- Posts: 2
- Joined: Sat Feb 04, 2023 1:35 am
Re: Warning - Could not instantiate mail function.
Thank you.toivo wrote: ↑Sat Feb 04, 2023 2:13 am@yumasan and @Paul Stalli, read the test results from viewtopic.php?f=810&t=994062#p3661154?
- rcarey
- Joomla! Explorer
- Posts: 471
- Joined: Sat Apr 25, 2009 9:20 pm
- Location: Minnesota (USA)
- Contact:
Re: Warning - Could not instantiate mail function.
Just publicly acknowledging that this thread led me to the solution... I have a client who wants to be on SiteGround, and when I moved the new site to that host, I witnessed the same problem/symptoms. Solution was to switch from PHP-Mail to SMTP.
Randy Carey -- as of 2023 I'm mostly retired in web development, but still engaged with a few Joomla projects through
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions
- toivo
- Joomla! Master
- Posts: 16938
- Joined: Thu Feb 15, 2007 5:48 am
- Location: Sydney, Australia
Re: Warning - Could not instantiate mail function.
@rcarey, thank you for this information! It will help Joomla users, who face a similar situation and who first search for a solution.
Toivo Talikka, Global Moderator