100 points- Mandrill with Membership Plugin

Can somebody paste a complete, working example of what I would need to enter in Remote Pings to subscribe a person, allow them to unsubscribe and send a message using Mandrill not Mailchimp? Url etc (just not your api key)

FYI-Mailchimp's terms of service doesn't allow us to use Mailchimp for transactional emails such as reminders, alerts, subscription renewals, ie triggered emails so it will be great to have a complete example set up for the community to use. 100 points for the working solution!

  • Charlie Pryor
    • The Incredible Code Injector

    Hi Atlanta,

    We've got an in-depth tutorial series created for Membership, in which one of the videos walks users through using Remote Pings. Specifically, I've used Mailchimp in the example presented.

    http://www.youtube.com/watch?v=1vRrWidibBg

    While this may not include the exact word-for-word setup you'll need for understanding how to do what you'd like to do, if you haven't watched this tutorial before, it may help.

    Thanks for being a WPMU DEV member!

    Charlie

  • Atlanta
    • Syntax Hero

    @Timothy Bowers
    Thanks, I am probably complicating it more than necessary:slight_smile:
    Here is an example of one of the areas where I am stuck:

    If a user joins a free subscription level, it looks like Membership> Communications is only set up to send an alert to the user, not the admin. I will like the admin to receive an email that there is a new member at one certain level, not my other levels.

    I set up a joining ping that sends an email to the admin when a user joins this level.

    I have wpmandrill installed on the subsite but I am not using it on the main or network site (I want to keep the subsite's transactional emails separate from the network emails smtp/ api account.

    The ping is at the root level of the site http://mysite.ping.php so when it goes out it doesn't use the Mandrill template sheet, unsubscribe options etc.

    I tried moving the ping to a subsite where the wpmandrill was installed
    mysite.com/wp-content/blogs.dir/243/ping.php but it didn't work.

    1) Is there an easy way to send a notification to the admin when a user joins this one level (and not other levels). Eg via Membership>Communications

    Or

    2) How do I set up subsite pings to use mandrill in this situation?

  • Timothy Bowers
    • Chief Pigeon

    I think I get what you want now.

    The Mandril plugin only replaces the WP mail function so that all mail goes through them.

    Because sending the admin a notification of a new member on a specific level is not part of Membership, it means you need to build something custom to handle that.

    My experience with Madrill is rather limited, but this appears like it should help:

    https://mandrillapp.com/api/docs/messages.html#method=send

    You could build up a JSON, XML or PHP file then have ping hit that. You'd need to do the code to pass the Username/UID over but it shouldn't be too complicated.

    The ping feature has options to get the required data to send over, you can use the following constants within the message body to embed database information.

    %blogname%
    %blogurl%
    %username%
    %usernicename%
    %useremail%
    %userid%
    %networkname%
    %networkurl%
    %subscriptionname%
    %levelname%
    %timestamp%

    Have you any code examples of what you've tried?

    Take care.

  • Atlanta
    • Syntax Hero

    @Timothy Bowers

    If I disconnect the wp-mandrill plugin the email goes out (not through mandrill).
    When I reconnect the wp-mandrill plugin the email doesn't go out.

    Downloading error logs now...

    How do I check that data is being passed through?

  • Timothy Bowers
    • Chief Pigeon

    Can you please send in:

    - Mark to my attention
    - Link back to this thread
    - Include admin/network access
    - Include FTP
    - Include any relevant URLS for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    As this is kinda custom, it might take a little longer. I'm out tomorrow, not sure if I'll be back early or late. Hopefully not late :slight_smile:

    Cheers.

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    I'm very sorry for the delay here. Tim has asked me to take a look at this, as he has been incredibly busy for the week. He's asked me to express his apologies as well.

    You might see a few emails coming in as I'm testing it. I will followup with you again here soon.

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    The main issue here was that you were using wp_load from within a subsite. Unfortunately the wp_mail function wasn't being plugged because the plugins settings were never loaded.

    I just moved everything your code to an admin-ajax function and updated the ping URL. So it's working now.

    You should see a new plugin file called "WPMU DEV Support Mandrill Ping" You can move this code anywhere else if it's more convenient. You can also delete the other mandrill ping php files.

    Let me know what you think.

    PS. There is actually a problem with your Mandrill template. You'll need to login to your Mandrill account and find out why the message body isn't being included in the email. The subject is coming through ok.

  • Atlanta
    • Syntax Hero

    Thanks @Alexander and Tim:slight_smile:

    I don't think that it is working, or at least I am still doing something wrong.

    Clarification needed...
    Am I supposed to use http://mysite/.... resources/mandrill_ping/index.php as the ping url? When I try to insert this as the direct ping url the email doesn't get sent.

    If I copy your plugin and move it to the root (naming it as alexander.php) http://mysite.com/alexander.php ping url it doesn't send the email either. I have tried with the plugin site and network activated also.

    So the only one that seems to be working is the original mandrill.php which is at the root, but that seems be still going through the old Wordpress settings, not through mandrill. The wpmandrill dashboard widget shows that no emails were sent and the mandrill newsletter template (even blank and without content) is not attached.

    Just to make sure that we are looking at the same subsite I was checking the testmresponsive sub site blog.

    I haven't changed the login info yet. Let me know if you need me to resend it again.

    Thanks:slight_smile:

  • Alexander
    • DEV MAN’s Mascot

    @Atlanta

    You don't ping the php file directly. The plugin description shows the URL to use. I believe I left it in the membership ping settings as well, but here it is again:

    It's something like this:
    domain.com/subsite/wp-admin/admin-ajax.php?action=mandrill_ping

    The other way would work fine, but only for the main site only. When simply creating a php file that includes wp-load.php, you're going to be working from the main site. That's why it wasn't working properly, because the Mandrill plugin was activated on the subsite.

    Registering the code to run under an admin-ajax.php action ensures that we can designate which site to run the ping through.

    Let me know if this clears things up.

    Best regards

  • Atlanta
    • Syntax Hero

    Thanks @Alexander Rohmann

    I have the ping url set to
    http://mysite.com/subsite/fashion-admin/admin-ajax.php?action=mandrill_ping
    The plugin is subsite activated.
    The ping history shows as 200 - OK
    But no email is sent.
    In your plugin file I replaced your email address in this field to
    $to = 'myemail@mail.com';//$admin_email;
    I also tried
    $to = 'mysite@mail.com';$admin_email; $_POST['useremail'];

    but no email was sent
    suggestions?

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    I just tried setting it back to my email address, and visiting the ping URL directly. I got an email doing this. It came from Mandrill with the proper template etc.

    I've set this back to your contact email address now. Can you try having a few pings fired off and let me know if you get any results.

    There seems to be some different commented out sections in the code. Who is the email intended for? the user, or the admin email address? If it's just the admin, that's already been retrieved earlier on so you can do:

    $to = $admin_email;

    Best regards

  • Atlanta
    • Syntax Hero

    Hmmm @Alexander Rohmann, I am still not receiving any emails and nothing is in my spam folder.

    I tried another email address just in case I accidentally unsubscribed but I still didn't receive an email. I also tried with a yahoo, gmail and my server email address.

    If I visit the ping url directly, like you did, the mandrill dashboard widget says that the email was sent, but again, I received no email.

    If I go to the subsite testmresponsive>All Members (admin.php?page=membershipmembers)and try to move a user's subscription to one of the Approved levels, I expect the email to be sent, because the mandrill test ping admin.php?page=membershippings&action=edit&ping=3 is selected for those levels, but the email isn't sent. Are these the same steps that you are taking?

    There seems to be some different commented out sections in the code. Who is the email intended for? the user, or the admin email address?
    One variation of the email is meant for the user.
    The other variation is meant for the sub site admin.

  • Alexander
    • DEV MAN’s Mascot

    @Atlanta,

    I think the primary issue here is that for some reason you can't receive the emails coming through from mandrill. I've just forwarded you a copy of the ping I get.

    I've only tested firing it directly at this point. But if we can't get it to send to your email address, then we need to figure that out before moving on.

    Can you perhaps try an email address on another domain? Or a gmail account?

    Best regards

  • Atlanta
    • Syntax Hero

    Hi @Alexander Rohmann

    Can you perhaps try an email address on another domain? Or a gmail account?
    I tried gmail, my server email, mail.com and yahoo mail. None of them worked for me.
    I also tried changing my location in case there was an ip conflict.
    Then I asked the server company to double check that The server company said that

    "It doesn't attempt to utilize the mail function on the server. I would advise to contact the script vendor to verify the set up."

    I also tried just entering the ping url in my address bar to see if I could get the ping to, fire directly, the way that I think you were doing it, but that doesn't work.

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    I'm sorry this has taken so long. I've tried several things here, and I believe this is actually a bug with the Membership plugin. I've done some testing on my own site and I'm seeing the same thing.

    I did discover I was actually wrong about the ping URL. We don't want the ping URL to include the ?action=mandrill_ping, as that conflicts with the rest of the HTTP request.

    However, no matter what I've tried, I can't get the ping to accept custom parameters. Ideally, we'd be able to add a line for "action=mandrill_ping" I'm going to touch base with the developer on this. Perhaps he can confirm it, or offer another solution.

    Best regards

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    I'm sorry for the delay - I've conferred with Barry on this, and we have a solution. Would you be ok with making a small change to one line of code in one of the membership core files? This change is already in a beta version, and will eventually be in an official release. It would enable these custom parameters. I could quickly add the change in so you wouldn't need to update to the beta version - that way you can just upgrade with official releases from here on out.

    Let me know. Thanks!

  • Alexander
    • DEV MAN’s Mascot

    Go to line 262 of class.ping.php

    You should see this:
    $pingdata = $this->pingconstants;

    Change to this:

    $pingdata = apply_filters('membership_ping_constants_list', $this->ping constants);

    Now we can add this to our plugin from before:

    //add action=mandrill_ping to our ping
    add_filter('membership_ping_constants_list','membership_custom_ping_constant');
    
    function membership_custom_ping_constant($constants) {
        $constants[] = 'action';
        return $constants;
    }
    
    add_filter('membership_pingfield_action','membership_mandrill_action');
    
    function membership_mandrill_action($filter) {
        return 'mandrill_ping';
    }

    This will allow us to use a ping URL of "domain.com/subsite/wp-admin/admin-ajax.php" The hooks will create the action=mandrill_ping for us, which will trigger the plugin we created earlier for sending the email.

  • Atlanta
    • Syntax Hero

    Arnold gave me this possible correction in live chat to prevent the server error....

    $pingdata = apply_filters('membership_ping_constants_list', $this->ping constants);

    $pingdata = apply_filters('membership_ping_constants_list', $this->pingconstants);

    Note no space at ping constants

    and then I pasted the add action code from above to the end of the original plugin that you created, as shown here http://pastebin.com/6Bjkq2f7

    but it still doesn't work.

  • Alexander
    • DEV MAN’s Mascot

    @Atlanta,

    First thing that comes to mind would be going to edit the ping, and adding this on the first line: action=mandrill_ping

    Also make sure the ping URL is http://yoursite.com/wp-admin/admin-ajax.php

    If thing doesn't work, would you mind re-enabling the FTP login, or sending new credentials for me? The filtering should work as I got that code from the Membership developer, and he's incorporated it for the latest release. (sorry about the space, must have happened when I copied/pasted or something)

    I'm not sure why the mandrill ping isn't firing as this should let us target the ajax action with a ping.

  • Alexander
    • DEV MAN’s Mascot

    Thanks for sending the login info. I've made a few changes and got this working. There was one little bug in the class.ping.php file that I fixed. There was an instance of "apply_filter" which needed to be "apply_filters" I've informed the developer so it can be included later as well.

    There's also one other small change to my code which I've corrected. I didn't set the constant key when adding it to the list. It needed to be added like: $constants['action'] = ''; instead.

    The only setting change I made was actually adding the "Mandrill test ping" as the joining ping to the subscription you have setup as public

    Try adding a member to that subscription and you should get an email.

    Best regards

  • Atlanta
    • Syntax Hero

    HI @Alexander, Thank you so much, it is wonderful to finally get to this stage where the email lands in my inbox! I really appreciate it. Thank you one million times over!!!

    Quick clarification question....
    I need to create 2 different pings.
    This first one works perfectly and sends a welcome message, thanks.

    How do I create a different welcome message ping for when a user joins another level?
    I tried copying your plugin to another folder mandrill_pingyay and then editing the welcome message but I'm not sure what ping url to use to set this ping off and not the other one. Suggestions?

  • Alexander
    • DEV MAN’s Mascot

    Hi @Atlanta,

    Duplicating the plugin would be the easiest way as you could activate on other sites if needed. You'd need to duplicate the plugin folder "mandrill_ping" and rename it. Then you need to go to index.php and change the "Plugin Name" in the header.

    Next, in this new duplicated version, replace all occurances of:

    mandrill_ping

    With a new identifier, (so mandrill_pingyay works) Then use that same identifier in the Membership Ping settings.

    Best regards

  • Atlanta
    • Syntax Hero

    Thanks @Alexander. I created the duplicate plugin, renamed the folder and the plugin title and I renamed all instances of mandrill_ping but got a fatal error:

    Fatal error: Cannot redeclare membership_custom_ping_constant() (previously declared in /mandrill_ping/index.php:15)

  • Alexander
    • DEV MAN’s Mascot

    As we're creating some new functions here, we'll need to make sure their names are unique as well. You could just name it "membership_custom_ping_constant_two" and update the reference to it in the hook as well. You'll need to do this for each function.

    Best regards,

  • Atlanta
    • Syntax Hero

    A deal is a deal... 100 points and 1 billion thank you's....

    thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.