craft()->on('email.onBeforeSendEmail', function (Event $event) {
// check if we've been here before
if (!isset($event->params['myplugin_beenHere'])) {
// do your stuff here
$event->params['myplugin_beenHere'] = true;
}
});
$variables = [
// any template variables
];
$htmlBody = /* Some HTML content, parsed by Twig?! */;
$plainTextBody = /* Some plain text content, parsed by Twig?! */;
craft()->mandrill
->addTo('[email protected]', 'Sender Name')
->setContent($htmlBody, $plainTextBody, $variables)
->send();
// get any UserModel anyhow, example:
$user = craft()->users->getUserByEmail('[email protected]');
$variables = [
// any template variables
];
craft()->mandrill
->setUser($user)
->setByEmailKey('the_message_key', $variables)
->send();
[
'user' => /* an UserModel */,
'emailModel' => /* an EmailModel */,
'variables' => /* an array of variables */,
// and on error:
'error' => /* error message */,
]
// attachment as content
craft()->mandrill
// ...
->addAttachment('my.pdf', $fileContents, 'application/pdf');
// or as a file path
craft()->mandrill
// ...
->addAttachmentFile('path/to/my.pdf', 'alternate-name.pdf', 'application/pdf')
craft()->on('email.onBeforeSendEmail', function (Event $event) {
// to be sure it happens when Mandrill is here
if (isset($event->params['_mandrill'])) {
// single one
$event->params['emailMessage']
->addTag('Tag name one')
->addTag('Tag name two');
// or as array
$event->params['emailMessage']
->addTag(['Tag name one', 'Tag name two']);
// based on messages-system email-key
switch ($event->params['variables']['emailKey']) {
case 'forgot_password':
$event->params['emailMessage']
->addTag('Forgot password');
break;
}
}
});
// attachment as content
craft()->mandrill
// ...
->addAttachment('my.pdf', $fileContents, 'application/pdf');
// or as a file path
craft()->mandrill
// ...
->addAttachmentFile('path/to/my.pdf', 'alternate-name.pdf', 'application/pdf')
craft()->on('email.onBeforeSendEmail', function (Event $event) {
// to be sure it happens when Mandrill is here
if (isset($event->params['_mandrill'])) {
$event->params['emailMessage']
->addAttachment('my.pdf', $fileContents, 'application/pdf');
}
});
$dateTime = new DateTime();
$dateTime->modify('+2 hours');
craft()->mandrill
// ...
->setSentAt($dateTime);
craft()->on('email.onBeforeSendEmail', function (Event $event) {
// to be sure it happens when Mandrill is here
if (isset($event->params['_mandrill'])) {
$dateTime = new DateTime();
$dateTime->modify('+2 hours');
$event->params['mandrillSentAt'] = $dateTime;
}
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.