Skip to content

Instantly share code, notes, and snippets.

@psorensen
Created August 8, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psorensen/e068a4eb31fe293f59f9df53aa365ab1 to your computer and use it in GitHub Desktop.
Save psorensen/e068a4eb31fe293f59f9df53aa365ab1 to your computer and use it in GitHub Desktop.
wpMandrill example send function
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(
array(
'rcpt' => 'one@email.com',
'vars' => array(
array('name' => 'fname', 'content' => 'Number One'),
array('name' => 'coupon', 'content' => '123456'),
)
),
array(
'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!'),
)
);
wpMandrill::sendEmail(
$message,
$tags = array('Tag 1', 'Tag 2'),
$template_name = 'MyCoolTemplate'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment