PHP code example of welp / mailjet-swiftmailer
1. Go to this page and download the library: Download welp/mailjet-swiftmailer 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/ */
welp / mailjet-swiftmailer example snippets
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret);
$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);
$transport->send($message);
$clientOptions = ['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => false];
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret, $clientOptions);
or
$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);
$headers = $message->getHeaders();
$headers->addTextHeader('X-MJ-TemplateID', $templateId);
$headers->addTextHeader('X-MJ-TemplateLanguage', true);
$vars = array("myFirstVar" => "foo", "mySecondVar" => "bar");
$headers->addTextHeader('X-MJ-Vars', json_encode($vars));
$emails = ['[email protected] ', '[email protected] ', '[email protected] ', '[email protected] ', '[email protected] ', '[email protected] ', ...]
$messages = [];
foreach ($emails as $email) {
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message
->addTo($email)
->addFrom('[email protected] ', 'From Name')
->addReplyTo('[email protected] ', 'Reply To Name')
;
array_push($messages, $message);
}
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret);
$result = $transport->bulkSend($messages);