[resolved] understanding wpMandrill:mail (8 posts)

  1. tstruyf
    Posted 3 years ago #

    I'm trying to use mpmandrill in my plugin. I'm trying to sent a mail with a specific template. I guess it should be possible using wpMandrill::mail . But I don't seems to find any examples or documentation about this function?

    This post (http://blog.mandrill.com/own-your-wordpress-email-with-mandrill.html) only seems to talk about filters, not the function. (And please note that this article has some broken images)

    Any help on getting started is welcome!

    thx in advance!


  2. tstruyf
    Posted 3 years ago #

    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) {
    array(1) {
    ["HTTP Code 500: https://mandrillapp.com/api/1.0/messages/send"]=>
    array(1) {
    string(0) ""
    array(0) {

  3. MC_Will
    Plugin Author

    Posted 3 years ago #


    Try to use this example as a starting point.

    I hope it helps,

    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 = 'one@email.com';
    	$globalmv = array(
    					array('name' => 'date', 'content' => 'Tomorrow morning!'),
    					array('name' => 'address', 'content' => 'Our office')
    	$mv	= array(
    					'rcpt' => 'one@email.com',
    					'vars' => array(
    									array('name' => 'fname', 'content' => 'Number One'),
    									array('name' => 'coupon', 'content' => '123456'),
    					'rcpt' => 'two@email.com',
    					'vars' => array(
    									array('name' => 'fname', 'content' => 'Number Two'),
    									array('name' => 'coupon', 'content' => '654321'),
    	$message = array(
    		'subject' => 'Email Subject',
    		'from_name' => 'Freedie',
    		'from_email' => 'your@email.com',
    		'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!'),
    		$tags = array('Tag 1', 'Tag 2'),
    		$template_name = 'MyCoolTemplate'
  4. Tony Schliesser
    Posted 3 years ago #

    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.

  5. MC_Will
    Plugin Author

    Posted 3 years ago #

    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.

  6. tstruyf
    Posted 3 years ago #

    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.

  7. Jupitercow
    Posted 2 years ago #

    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...

  8. lacom
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • wpMandrill
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic