Support » Plugin: WP Gmail SMTP » WooCommerce emails sending VIA the server not Gmail

  • Resolved CurtisN

    (@curtisn)


    Hello,
    Thank you for the great plugin. We have been using it for a while and everything has worked great until a recent update.

    Now WooCommerce is not sending emails through your plugin but rather from the server.

    I have read through other posts about similar issues and have tried those solutions I could find that seemed appropriate for my situation.

    I am using…
    Gmail SMTP v1.2.0
    WooCommerce v5.0.0
    Wordpress v5.6.2

    No new plugins have been added.

    Since GSMTP uses wp_mail() and so does WC, I’m guessing GSMTP is supposed to catch calls to wp_mail maid by other plugins (like WC). The behavior I am seeing indicates that something has gone wrong and WC is now overriding GSMTP’s setting. Just a thought.

    Whatever the case I am stuck and hope you can help.

    Please let me know if you need any info.

    Thanks!

    EDIT:
    Forgot to mention that the Test function from GSMTP is working. Emails received are from the gmail account. Whereas emails from WC are from the gmail account VIA the server.

    EDIT:
    Did some digging and testing in GSMTP’s code and see where the wp_mail() function is used/over-ridden.

    Looking at line 582 in main.php I modified this for a test.
    I removed the function_exists() check on wp_mail.
    I then sent a test email from GSMTP. This email was sent and received without issue.
    I then sent an email from WC and received this PHP Error:
    [24-Feb-2021 22:43:14 UTC] PHP Fatal error: Cannot redeclare wp_mail() (previously declared in ../wp-includes/pluggable.php:171) in ../wp-content/plugins/gmail-smtp/main.php on line 584

    This test indicates that the version of wp_mail implemented in GSMTP is never declared/used when WC loads and calls wp_mail but is declared/used when GSMTP calls wp_mail.

    • This topic was modified 3 months, 4 weeks ago by CurtisN.
    • This topic was modified 3 months, 3 weeks ago by CurtisN.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Noor Alam

    (@naa986)

    @curtisn, wp_mail is a pluggable function. Pluggable functions let you override certain core WordPress functions via plugins. However, a function can only be reassigned this way once, so you can’t have two plugins that plug the same function for different reasons.

    As far as I know core WooCommerce doesn’t define wp_mail. Do you have any other plugin that could cause this issue?

    Thread Starter CurtisN

    (@curtisn)

    I got a chance to do more debugging and need to apologize for implying that the error I encountered was the fault of your plugin. Turns out it’s not.

    Based on the error I listed in my first post I looked at the docs for ../wp-includes/pluggable.php and realized that another plug-in is either declaring wp_mail() before GSMTP or is causing ../wp-includes/pluggable.php to be loaded before GSMTP can load its version of wp_mail().

    GREPing the code in the plugins folder revealed a few plugins that were loading ../wp-includes/pluggable.php directly.

    One of these is alphabetically before GSMTP and since WP loads plugins in alphabetical order when the offending plugin is enabled it loads before GSMTP and causes this error. This has likely always been true and we simply never realized it because this plugin is usually disabled.

    As I have no interest in forking the offending plugin to fix it so it does not load ../wp-includes/pluggable.php directly (seems like a bad idea to load pluggable.php for one function), I wrote a patch for my theme’s functions.php.

    In testing I wrote a function that, if added to the beginning of GSMTP, will cause GSMTP to load before all other plugins by re-ordering the active-plugins array in the db.

    It seems stupid that you should have to compensate for other people’s coding choices but if this is of interest to you, you can see the code at https://gist.github.com/curtisnehring/8d11437ab5c403d1903277f5da740588

    Thanks for making your plugin freely available. I really appreciate it!

    For others who run into this type of issue and stumble on this post, the function I am using in my theme’s functions.php can be seen at https://gist.github.com/curtisnehring/0241c35ee77744137d8adf17c099c480

    • This reply was modified 3 months, 3 weeks ago by CurtisN.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.