WordPress.org

Forums

wpMandrill
[resolved] Trouble adding tags on mandrill payload function (8 posts)

  1. evan3168
    Member
    Posted 1 year ago #

    I feel like I'm going crazy here with this basic function I want to fire on mandrill_payload to add some tags to my emails.

    Here is my code:

    function dpg_mandrill_tag($message){
    
    	$message['tags'] = 'frankdougdog';
    	return $message;
    }
    
    add_filter('mandrill_payload', 'dpg_mandrill_tag');

    When I send using that code, NO tags show up, let alone the one I tried to add there. I tried diving into the wpmandrill core php files to get a better understanding, but I am at a loss for why the tag won't pass along. Help anyone?!

    http://wordpress.org/plugins/wpmandrill/

  2. MC_Will
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Evan,

    $message['tags'] is an array of arrays of arrays. Its values are $message['tags']['user'], $message['tags']['general'], and $message['tags']['automatic'].

    You're not supposed to modify the automatic tags (but you could if that's what you really want.)

    General tags are the ones added in the plugin's settings page.

    And 'user' are tags usually added by the wpmandrill_payload filter.

    That say, try something like

    function dpg_mandrill_tag($message){
    
    	$message['tags']['user'][] = 'frankdougdog';
    	return $message;
    }
    
    add_filter('mandrill_payload', 'dpg_mandrill_tag');
  3. evan3168
    Member
    Posted 1 year ago #

    Ah beautiful! I saw that the user, general, and automatic tags were merged in the core plugin so I thought by the time they reached mandrill_payload it was all one array.

    Your adjustment to my function works perfectly, thank you so much for the help!

  4. evan3168
    Member
    Posted 1 year ago #

    Hey Will gonna ask for your help just one more time... what would be the best way to pass an array of tags into the payload?

  5. evan3168
    Member
    Posted 1 year ago #

    Ah nevermind, found a quick way to do it.

    function dpg_mandrill_tag($message){
    
    	$newtags = array( "frankdougdog","arri-alexa" );
    
    	foreach( $newtags as $tag ) {
    
    		$message['tags']['user'][] = $tag;
    
    	}
    
    	return $message;
    }

    P.S. Sorry for the barrage of messages :)

  6. MC_Will
    Member
    Plugin Author

    Posted 1 year ago #

    Hey,

    I guess the best option will be to use the array_merge function.

    function dpg_mandrill_tag($message){
    	$message['tags']['user'] = array_merge($message['tags']['user'], array("frankdougdog","arri-alexa"));
    	return $message;
    }
  7. Deepak Mahendru
    Member
    Posted 1 year ago #

    Hi,

    How can I get my code work using wpmandrill ?? Actually the problem is my mails are going to spam folder and I want them to go in Inbox... please help ...thanks

    add_filter('mandrill_payload', 'user_role_update');
    function user_role_update( $user_id, $new_role ) {
    if ($new_role == 'member') {
    $site_url = get_bloginfo('wpurl');
    $user_info = get_userdata( $user_id );
    $to = $user_info->user_email;
    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "Organization: Organization \r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";

    $headers .= "X-Priority: 1 (Highest)\n";
    $headers .= "X-MSMail-Priority: High\n";
    $headers .= "Importance: High\n";

    // Additional headers
    $current_user = wp_get_current_user();

    $headers .= 'From: '.$current_user->user_firstname.' '.$current_user->user_lastname.' <'.$current_user->user_email.'>,';
    $headers .= '\r \n';
    $headers .= 'Reply-To: '.$to;
    $headers .= '\r \n';
    $headers .= 'Return-Path: '.$current_user->user_firstname.' '.$current_user->user_lastname.' <'.$current_user->user_email.'>,';

    $subject = "Congratulations. You have been approved!";
    $message = "";
    wp_mail($to, $subject, $message, $headers);
    }

    }
    add_action( 'set_user_role', 'user_role_update', 10, 2);
    // add_action( 'profile_update', 'user_role_update', 10, 2);

  8. MC_Will
    Member
    Plugin Author

    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • wpMandrill
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.