Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter tstruyf

    (@tstruyf)

    I got a bit off progress, but I’m trying to send a template, but run into various problems.

    I found the requested parameters by digging trough wpmandrill’s plugin files. I use this function with all my varriables set:

    $result = wpMandrill::mail($to, $subject, $html, $headers, $attachments, $tags, $from_name, $from_email, $template_name,$track_opens,$track_clicks,$url_strip_qs,$merge,$global_merge_vars,$merge_vars);

    I got 4 standard templates. If try them, only 1 template sends an actual HTML mail. The others just sends the string which I’ve set in $html).

    If I try to alter a variable (defined in template), I do this:
    $global_merge_vars = array(‘woon_test1’=>’testcontent bla bla bla’);

    and then $results contains this:

    object(WP_Error)#1210 (2) {
    [“errors”]=>
    array(1) {
    [“HTTP Code 500: https://mandrillapp.com/api/1.0/messages/send”%5D=>
    array(1) {
    [0]=>
    string(0) “”
    }
    }
    [“error_data”]=>
    array(0) {
    }
    }

    Plugin Author MC_Will

    (@mc_will)

    Hello,

    Try to use this example as a starting point.

    I hope it helps,
    Will

    function SendTemplate() {
    	// Create a template called MyCoolTemplate and use this code:
    	$template_code = '
    	Hello *|FNAME|*,
    
    	<p>Your personal coupon code is: *|COUPON|*</p>
    
    	<p>Event Date: *|DATE|*</p>
    	<p>Address: *|ADDRESS|*</p>  
    
    	<div mc:edit="body"></div>
    	<div mc:edit="sidebar"></div>
    	';
    
    	// Sending an email using a template and merge vars
    	$to = '[email protected]';
    	$globalmv = array(
    					array('name' => 'date', 'content' => 'Tomorrow morning!'),
    					array('name' => 'address', 'content' => 'Our office')
    				);
    	$mv	= array(
    				array(
    					'rcpt' => '[email protected]',
    					'vars' => array(
    									array('name' => 'fname', 'content' => 'Number One'),
    									array('name' => 'coupon', 'content' => '123456'),
    								)
    				),
    				array(
    					'rcpt' => '[email protected]',
    					'vars' => array(
    									array('name' => 'fname', 'content' => 'Number Two'),
    									array('name' => 'coupon', 'content' => '654321'),
    								)
    				),
    			);
    	$message = array(
    		'subject' => 'Email Subject',
    		'from_name' => 'Freedie',
    		'from_email' => '[email protected]',
    		'to' => $to,
    		'merge' => true,
    		'global_merge_vars' => $globalmv,
    		'merge_vars' => $mv,
    		'html' => array(
    						array('name' => 'body', 'content' => 'This is the body!'),
    						array('name' => 'sidebar', 'content' => 'This is the sidebar!'),
    					)
    	);
    	wpMandrill::sendEmail(
    		$message,
    		$tags = array('Tag 1', 'Tag 2'),
    		$template_name = 'MyCoolTemplate'
    	);
    }

    I’m just getting my feet wet with wordpress dev and wpmandrill, so forgive the rookie question – Where does that function go? I’ve grep’ed for it in the plugin but didn’t see it.

    Plugin Author MC_Will

    (@mc_will)

    Hi Tony,

    That function is just a skeleton function of what you should do to use the Mandrill Template System within wpMandrill. You probably need the basic functionality only.

    So based on your previous question, I think all you need to do is to create a template with a a mc:edit=”main” pseudo-tag added to any container tag and it will work with the standard WP emails your installation sends.

    So just try this:
    1) Log into your Mandrill account.
    2) Create a new template. Call it ‘WP Emails’
    3) Add the following code to that template:

    <div mc:edit="main"></div>

    4) Save it.
    5) Back in your WP installation, go to your wpMandrill settings page.
    6) Select ‘WP Emails’ as the default template.
    7) Save it.
    8) Test all your WP Emails.

    Thread Starter tstruyf

    (@tstruyf)

    Sorry for the late answer, but your code did help me out, Thx MC_Will!

    My example is working now, but I still find the documentation is lacking some clear examples. Using the documentation and without you telling me how to use wpMandrill::sendEmail, I could never get it working.

    This doesn’t work at all for me. I have tried:

    <div mc:edit="main"></div>

    <div mc:edit="body"></div>

    <div mc:edit="body_content"></div>

    Nothing gets the email message to show up in the template. I had to move the text to a merge tag. It frustrating that Mandrill doesn’t give a solid example of a template. The documentation is so hard to navigate right now…

    Thanks all who’ve posted in this thread. It’s been helpful. I would like to add that the $template_name param in ::sendEmail() should be set to the actual template name, and NOT the template slug. I was stuck on this for a bit because in the Mandrill template interface, the subtext below the Template Slug field says that the slug name is what is used for API calls. However, this is not the case for the WP plugin — it’s the Template Name that is used.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘understanding wpMandrill:mail’ is closed to new replies.