• Emails sent from my site by WordPress intermittently fail. The error message shown by WP Mail Logging plugin is “Could not instantiate mail function”. The emails fail both from our Contact Us page, and from comments added to WordPress Posts. It is intermittent, so it sometimes works.

    I (may) have narrowed the focus to the /usr/sbin/sendmail bash script, which is 38 lines long! (Not 100% sure that is what my system uses though.)

    Is there a level of logging or error reporting that I can enable to understand better why this is happening? (Already tried enabling “display errors” and “error_reporting” in cPanel “PHP Selector”, but that seemed to have no effect.)

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi, @rswick

    The ‘Could not instantiate mail function error message is a generic one that various issues can cause. To better understand the cause of this error, you can try the following steps:

    1. Check the web server and PHP error logs for any messages related to the email function. This can help to identify any issues with the web server or PHP configuration.

    2. Inspect the Sendmail script to ensure that it is correctly configured and that it is being invoked correctly.

    3. Verify that your email server is running correctly and configures to accept emails from your web server.

    4. Verify the SMTP credentials being used and ensure they have the correct permissions.

    5. Check your DNS or MX records of the email address you are sending emails from and ensure they are configured correctly.

    6. Test your email-sending functionality using a different mailer, such as the PHP mail() function or a third-party library like PHPMailer or SwiftMailer.

    7. Contact your hosting provider support team for a specific direction to help you with your specific server setup.

    8. Search for your error message in the WordPress community to see if other users have had similar issues and how they resolved them.

    By following these steps, you can identify the cause of the ‘Could not instantiate mail function error message and take the necessary steps to resolve it.
    Thank you.

    Thread Starter rswick

    (@rswick)

    Thanks for the reply. Regarding:

    >>1. Check the web server and PHP error logs for any messages related to the email function. This can help to identify any issues with the web server or PHP configuration.

    I have already looked at ~/public_html/error_log and ~/public_html/wp-admin/error_log. Are there any other log files I should look at?

    Thread Starter rswick

    (@rswick)

    Thanks!

    Regarding:

    >>2. Inspect the Sendmail script to ensure that it is correctly configured and that it is being invoked correctly.

    I don’t know which script is the sendmail script. How would I determine that? And how would I know if it is correctly configured and being invoked correctly?

    Please note that the problem is intermittent. To me, that means the cause has to be something intermittent as well. I believe scripts are *fixed* – meaning they do not change.

    • This reply was modified 1 year, 10 months ago by rswick. Reason: formatting incorrect
    Thread Starter rswick

    (@rswick)

    Regarding:

    >> 3. Verify that your email server is running correctly and configures to accept emails from your web server.

    4. Verify the SMTP credentials being used and ensure they have the correct permissions.

    5. Check your DNS or MX records of the email address you are sending emails from and ensure they are configured correctly.

    6. Test your email-sending functionality using a different mailer, such as the PHP mail() function or a third-party library like PHPMailer or SwiftMailer.`

    <<

    As mentioned, the emails fail only *intermittently*. They also work. So I do not see how these apply.

    • This reply was modified 1 year, 10 months ago by rswick.
    Thread Starter rswick

    (@rswick)

    Regarding:

    >>8. Search for your error message in the WordPress community to see if other users have had similar issues and how they resolved them.

    I did this before I posted to the forum. None of the posts from other users mentioned an *intermittent* issue and the resolutions did not seem relevant to my situation.

    Regarding:

    >>7. Contact your hosting provider support team for a specific direction to help you with your specific server setup.

    I can do that also, but was hoping for help from this forum. The problem is right now contained to WordPress.

    Specifically, as mentioned, is there a level of logging or error reporting that I can enable to understand better what is going wrong?

    Thread Starter rswick

    (@rswick)

    FYI. I disabled Akismet Anti-Spam 5.0.2 plugin. After I did that the emails started working every time, instead of intermittently failing.

    I think the problem may have started with Akismet 5.0, which I installed on August 4, 2022. That release is described as, “Added a new feature to catch spammers by observing how they interact with the page.”

    WP Mail Logging shows only emails marked as “[spam]” give the “could not instantiate mail function” error. Also, some emails marked as “[spam]” do NOT give the error.

    So the problem is with Akismet Anti-Spam 5.0.2.

    Thread Starter rswick

    (@rswick)

    My previous update was incorrect. Though Akismet Anti-Spam plugin is Inactive, the “could not instantiate mail function” error is still occurring. Though less frequently. As shown by WP Mail Logging log.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @rswick Unless it’s spam, abuse or something broken in the forums please do not report topics again.

    It is not a means to get faster support, it only gets forum moderators attention and no one else.

    Please do not bump.

    Thread Starter rswick

    (@rswick)

    Regarding this suggestion:

    >>7. Contact your hosting provider support team for a specific direction to help you with your specific server setup.

    I had a long conversation with my provider’s technical support. The outcome was that we changed the cPanel email routing from “local mail exchanger” to “remote mail exchanger” and downgraded PHP from 8.0 to 7.4. The support person was certain we had found the solution.

    However, after the phone call the problem resumed. Sending of emails is intermittently failing with the “could not instantiate mail function.” error, as shown by WP Mail Logging plugin.

    I have also re-activated Akismet Anti-Spam plugin. As that was not the cause of this problem.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Intermittent “could not instantiate mail function” error when sending email’ is closed to new replies.