PHP code example of a2design-company / mandrill-cakephp-plugin
1. Go to this page and download the library: Download a2design-company/mandrill-cakephp-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
a2design-company / mandrill-cakephp-plugin example snippets
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('mandrill');
$email->to('[email protected]');
$email->subject('Test email via Mandrill');
$email->send('Message');
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail(array(
'transport' => 'Mandrill.Mandrill',
'from' => '[email protected]',
'fromName' => 'FromName',
'timeout' => 30,
'api_key' => 'YOUR_API_KEY',
'emailFormat' => 'both',
));
$viewVars = array(
'var1' => 'some1',
'var2' => 'some2'
);
$to = array(
'[email protected]',
'[email protected]',
);
$email->addHeaders(array(
'tags' => array('test',),
'subAccount' => 'YOUR_SUBACCOUNT',
'preserve_recipients' => false,
'global_merge_vars' => array(
array(
'name' => 'date',
'content' => date('Y-m-d'),
),
),
'merge_vars' => array(
array(
'rcpt' => '[email protected]',
'vars' => array(
array(
'name' => 'email',
'content' => '[email protected]'
),
array(
'name' => 'name',
'content' => 'to1Name'
),
)
),
array(
'rcpt' => '[email protected]',
'vars' => array(
array(
'name' => 'email',
'content' => '[email protected]'
),
array(
'name' => 'name',
'content' => 'to2Name'
),
)
),
),
));
$email->addAttachments(array(
'example.pdf' => array(
'file' => APP . '/webroot/files/readme.pdf',
'mimetype' => 'application/pdf',
),
'logo.png' => array(
'file' => APP . '/webroot/img/logo.png',
'mimetype' => 'image/png',
// 'contentId' => 'headerLogo', // Uncomment this line if you want use inline image
));
$email->template('test', 'default');
$email->viewVars($viewVars);
$email->to($to);
$email->subject('Mandrill CakePHP Plugin Test');
$email->send();
CakePlugin::load('Mandrill');
class EmailConfig {
public $mandrill = array(
'transport' => 'Mandrill.Mandrill',
'from' => '[email protected]',
'fromName' => 'FromName',
'timeout' => 30,
'api_key' => 'YOUR_API_KEY',
'emailFormat' => 'both',
);
}