Warning - Could not instantiate mail function. Topic is solved

Need help installing Joomla! 4.x? For all Joomla! 4.x installation issues please use this forum.

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
Post Reply
User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 1:38 pm

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

User avatar
ceford
Joomla! Ace
Joomla! Ace
Posts: 1368
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Warning - Could not instantiate mail function.

Post by ceford » Thu May 26, 2022 2:09 pm

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.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 42124
Joined: Sat Apr 05, 2008 9:58 pm

Re: Warning - Could not instantiate mail function.

Post by Webdongle » Thu May 26, 2022 2:28 pm

jd-morris wrote:
Thu May 26, 2022 1:38 pm
...

I set up with both reCAPTCHA V2 and V3, no luck....
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".

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15241
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Warning - Could not instantiate mail function.

Post by toivo » Thu May 26, 2022 2:30 pm

Is the contact form you tested from the Joomla core Contacts component or from a third party extension?
Toivo Talikka, Global Moderator

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 2:46 pm

jd-morris wrote:
Thu May 26, 2022 1:38 pm
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
ceford wrote:
Thu May 26, 2022 2:09 pm
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.
Thank you, I set this, where is stack trace code?

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 2:48 pm

toivo wrote:
Thu May 26, 2022 2:30 pm
Is the contact form you tested from the Joomla core Contacts component or from a third party extension?
This is a Rocketheme template with the standard Contact Component, I've done this before which is why I'm confused...

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 2:49 pm

Webdongle wrote:
Thu May 26, 2022 2:28 pm
jd-morris wrote:
Thu May 26, 2022 1:38 pm
...

I set up with both reCAPTCHA V2 and V3, no luck....
Most often it is using the wrong captcha keys
Thank you, I regenerated new keys just in case, that didn't help...

User avatar
ceford
Joomla! Ace
Joomla! Ace
Posts: 1368
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Warning - Could not instantiate mail function.

Post by ceford » Thu May 26, 2022 3:23 pm

jd-morris wrote:
Thu May 26, 2022 2:46 pm
ceford wrote:
Thu May 26, 2022 2:09 pm
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.
Thank you, I set this, where is stack trace code?
It should be immediately following the Warning - Could not instantiate mail function message.

Unless that is showing in a System message. A screenshot would be useful. And the System - Debug plugin needs to be enabled.

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 3:58 pm

ceford wrote:
Thu May 26, 2022 3:23 pm
jd-morris wrote:
Thu May 26, 2022 2:46 pm
ceford wrote:
Thu May 26, 2022 2:09 pm
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.
Thank you, I set this, where is stack trace code?
It should be immediately following the Warning - Could not instantiate mail function message.

Unless that is showing in a System message. A screenshot would be useful. And the System - Debug plugin needs to be enabled.
I enabled the Debug Plugin, set Error Reporting to Maximum, I received the same error message
You do not have the required permissions to view the files attached to this post.

User avatar
ceford
Joomla! Ace
Joomla! Ace
Posts: 1368
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Warning - Could not instantiate mail function.

Post by ceford » Thu May 26, 2022 5:17 pm

Clutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:

Code: Select all

            $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
...
        if (!$result) {
            throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
        }
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.

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 5:57 pm

ceford wrote:
Thu May 26, 2022 5:17 pm
Clutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:

Code: Select all

            $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
...
        if (!$result) {
            throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
        }
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.
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.
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.

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 6:04 pm

jd-morris wrote:
Thu May 26, 2022 5:57 pm
ceford wrote:
Thu May 26, 2022 5:17 pm
Clutching at straws! I think you would trigger this message if any one of the mail form parameters is empty:

Code: Select all

            $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
...
        if (!$result) {
            throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
        }
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.
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.
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.
Here's The everything.php
#
#<?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: "info@consulting-japan.com" <info@consulting-japan.com>
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 <jdmorris@consulting-japan.com>
Reply-To: John <johndmorris2005@gmail.com>
Message-ID: <FCCrioYEtM037NJmlDrEjuZv5CfcZ3JFZlA1OdH0IjE@www.consulting-japan.com>
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: "info@consulting-japan.com" <info@consulting-japan.com>
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 <jdmorris@consulting-japan.com>
Reply-To: John <johndmorris2005@gmail.com>
Message-ID: <AL00avESiljI5UJ9h1d2Lw1PJUlXTRZssS22uIbSf0w@www.consulting-japan.com>
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}

User avatar
ceford
Joomla! Ace
Joomla! Ace
Posts: 1368
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Warning - Could not instantiate mail function.

Post by ceford » Thu May 26, 2022 8:01 pm

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?

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Thu May 26, 2022 8:17 pm

ceford wrote:
Thu May 26, 2022 8:01 pm
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?
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.
I temporarily disabled my contact form as I've been up all night.
Image[/img]I hope someone can figure this out with the data I provided.
You do not have the required permissions to view the files attached to this post.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 42124
Joined: Sat Apr 05, 2008 9:58 pm

Re: Warning - Could not instantiate mail function.

Post by Webdongle » Thu May 26, 2022 9:26 pm

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

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function.

Post by jd-morris » Fri May 27, 2022 1:27 am

Webdongle wrote:
Thu May 26, 2022 9:26 pm
Have you tried without the captcha?
Yes, I sure have, my apologies for not adding this, I changed the captcha between V2 & V3, when to my Google account verified my captcha, generated new captcha, then disabled captcha...that didn't work.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15241
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Warning - Could not instantiate mail function.

Post by toivo » Fri May 27, 2022 2:25 am

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
Toivo Talikka, Global Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15241
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Warning - Could not instantiate mail function.

Post by toivo » Fri May 27, 2022 3:12 am

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.
Toivo Talikka, Global Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15241
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Warning - Could not instantiate mail function.

Post by toivo » Fri May 27, 2022 6:33 am

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:
thank-you-for-your-email.jpg

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:

could-not-instantiate-mail-function.jpg

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

User avatar
jd-morris
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Apr 21, 2010 5:57 pm
Location: Tokyo
Contact:

Re: Warning - Could not instantiate mail function. [Solved]

Post by jd-morris » Fri May 27, 2022 6:59 am

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!
Last edited by jd-morris on Fri May 27, 2022 7:07 am, edited 1 time in total.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15241
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Warning - Could not instantiate mail function.

Post by toivo » Fri May 27, 2022 7:11 am

Good to hear, thank you for the update!
Toivo Talikka, Global Moderator

yumasan
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 131
Joined: Wed Jul 29, 2009 3:33 pm
Contact:

Re: Warning - Could not instantiate mail function.

Post by yumasan » Thu Oct 06, 2022 4:05 pm

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?

yumasan
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 131
Joined: Wed Jul 29, 2009 3:33 pm
Contact:

Re: Warning - Could not instantiate mail function.

Post by yumasan » Thu Oct 06, 2022 4:25 pm

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.


Post Reply

Return to “Installation Joomla! 4.x”