What is the best method to send any and all email from the website by mandrill api?

Hey all,

What is the best method to send any and all email from the website by mandrill api? I know there are several type of calls WP or WP plugins can use to send php/internal website mail. I would like to send absolutely all email via mandrill. Some plugins allow for naming smtp, but many do not (including Subscribe By Email) . . . for example, wp_mail() function or mail() functions etc.

I have looked at several plugins from another thread I started specifically on Subscribe By Email inquiry, but I have found none of them to work well (or they will only send for some methods and not others etc). I am looking for a all encompassing final solution to solve all outbound email issues will all plugins so that they will all actually work without worry about if they will have issues day-to-day...smile.

Similar Ref: https://premium.wpmudev.org/forums/topic/subscribe-by-email-via-mandrill

A proven/reliable way to do it per site AND alternately network-wide would be helpful.

:slight_smile:

  • Jose

    Hi there @Greg,

    The official wpMandrill plugin should work in the way that you are describing:
    https://wordpress.org/plugins/wpmandrill/

    This plugin will completely override the WP native wp_mail() method.
    Therefore, all the mails sent from WP and any other plugin using wp_mail() will be sent via Mandrill API. -of course, if there is a plugin that implements a custom method to send email, you will need to get into the code and fix it, but it is expected that every plugin will try to use wp_mail before implementing cusotm methods-.

    I just ran a quick test using Subscribe by Email and wpMandrill and all the emails went through Mandrill API.

    Now, wpMandrill plugin implements a fallback to the native wp_mail function in case anything goes wrong when trying to send the message via Mandrill API.
    If you already tried this plugin but your emails were sent from yur server, then you are probably having some error communicating with Mandrill API.

    Please let me know if you are having some specific error using this approach and I'll be glad to log into your site and take a look for you. :slight_smile:

    Cheers!
    Jose

  • Jose

    Hey @Greg,

    If you are using SMTP mode in eNewsletter and it is configured using your Mandrill smtp settings, that's ok. No need to change anything in that front.

    The error "wp_mail has been declared by another process or plugin" means that, when wpMandrill tries to declare the custom wp_mail method, it is already declared. This is how it works inside wpMandrill:

    if( function_exists('wp_mail') ) {
                self::$conflict = true;
                add_action('admin_notices', array(__CLASS__, 'adminNotices'));
    			return;
    }

    Then, one way to fix this is would be to hack the plugin loading order to ensure that wpMandrill is loaded first. I'm attaching a must use plugin that will do it for you.
    Just drop the php file into the following location:
    ../wp-content/mu-plugins/
    (create the folder if it doesn't exists)
    Edited: After installing the mu-plugin, you need to activate-deactivate a plugin, in order to triggger 'activated_plugin' hook.

    This would be a quick way to fix it, but still has some possible downsides: If the plugin that is declaring the wp_mail function doesn't check if it is already declared, it will override it.

    The ideal way to go about this would be to find the plugin that is declaring wp_mail and deactivate it.
    To achieve this, I would suggest to first disable all the mail-related plugins and check if the error gone. Then activate one at a time.
    Another way, if you have your site's files set in a local project, would be to search for occurrences of 'function wp_mail' into your plugin files.

    Let me know if the mu-plugin solves the issue. If not, I'll be glad to assist you to find the plugin causing the conflict.

    Cheers!
    Jose

    Just for reference, this is the code for the mu-plugin:

    if(! class_exists('Change_Plugin_Order') ):
    
        class Change_Plugin_Order{
    
            function __construct(){
                add_action( 'activated_plugin' , array( $this, 'this_plugin_first'), 10, 2);
            }
    
            public function this_plugin_first($plugin, $network_activation) {
                $path = 'wpmandrill/wpmandrill.php';
                if ( $plugins = get_option( 'active_plugins' ) ) {
                    if ( $key = array_search( $path, $plugins ) ) {
                        array_splice( $plugins, $key, 1 );
                        array_unshift( $plugins, $path );
                        update_option( 'active_plugins', $plugins );
                    }
                }
            }
    
         }
        new Change_Plugin_Order;
    endif;
  • Greg

    @Jose

    After adding the mu-plugins folder and putting the code in, at first, I refreshed and it did not work. I deactivate and reactivated the mandrill plugin and the error did go away after that.

    I tried disabling each mail plugin I could see on both the individual subsite and main network site for multisite. At first, I did them one by one and refreshed the screen but no error went away. After I found out the mu_plugin file did not work by refresh either, I went back and did each one again but also deactivate and reactivated the mandrill plugin to by sure that was not the reason why one of the mail-type plugins did not reveal itself as the culprit (however, the error still remained to my disappointment).

    For now, I am using the mu_plugin file just to try it out etc.

    But, yea, if you could help to do it the way we really should then that would be great.

    ***Right now, I am searching all the plugin folders for "function wp_mail" to see what that comes up with as well fyi...currently it is about halfway done searching...UPDATE: nothing found via ftp in the plugin folder.

    Support Access is enabled by the way...

    Let me know...

    :slight_smile:

    Greg

  • Jose

    Hey @Greg,

    Yeah, I forgot to mention that you need to activate some plugin in order to trigger the hook 'activated_plugin'.

    If it is working fine for you with the mu-plugin, you should good to go then.

    nothing found via ftp in the plugin folder

    As far as I know, the ftp client search will look only into file names, not into file content.
    Just want to be sure that you are running a search into file content.

    Cheers,
    Jose

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.