Run from terminal:
$ composer require axelero/axelero-mailgun-bundleEnable bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Axelero\MailgunBundle\AxeleroMailgunBundle()
);
}Add following lines in your configuration:
# app/config/config.yml
axelero_mailgun:
domain: 'your-domain'
api_key: 'your-api-key'
# app/config/config_dev.yml
axelero_mailgun:
domain: 'your-sandbox-domain'
api_key: 'your-sandbox-api-key'Otherwise the default value post will be used.
Example:
...
//collecting the recipients
$recipients = [
[
'email' => 'first@email.com',
'first' => 'firstName',
'last' => 'lastName'
],
[
'email' => 'second@email.com',
'first' => 'anotherName',
'last' => 'anotherSurname',
'myCustomData' => 'customValue',
'anotherCustom' => ['my', 'data'],
],
];For myCustomData see [https://github.com/mailgun/mailgun-php/blob/v1.8/src/Mailgun/Messages/README.md]
By default you can send mails with the account configured in your config.yml
$this->get("axelero_mailgun.gunman")
->batchSend('from@email.com', 'mailTitle', '<h1>Your Content</h1>', $recipients);Otherwise you can configure api parameters at runtime
$this->get("axelero_mailgun.gunman")
->setKey($key)
->setDomain($domain)
->batchSend('from@email.com', 'mailTitle', '<h1>Your Content</h1>', $recipients);