Source of file SendinBlueTransport.php
Size: 3,395 Bytes - Last Modified: 2021-12-23T10:59:13+00:00
/var/www/docs.ssmods.com/process/src/code/Transport/SendinBlueTransport.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | <?php namespace WebTorque\QueuedMailer\Transport; class SendinBlueTransport implements Transport { /** * @var \Sendinblue\Mailin */ private $mailin; /** * IP Address of SendinBlue server * @var string */ private $ipAddress; public function __construct($url, $accessKey, $ipAddress = null) { $this->mailin = new \Sendinblue\Mailin($url, $accessKey); $this->ipAddress = $ipAddress; } /** * @param string $app Name of app sending email * @param string $identifier Unique identifier for the email * @param string $to * @param string $from * @param string $subject * @param string $html * @param string $plain * @param string $cc * @param string $bcc * @param array $attachments * @param array $headers * @param string|null $replyTo * @return bool|array */ public function send($app, $identifier, $to, $from, $subject, $html, $plain, $cc, $bcc, $attachments, $headers, $replyTo = null) { if (empty($headers)) $headers = array(); //add some extra info for tracking etc $headers['X-Mailin-custom'] = $identifier; $headers['X-Mailin-Tag'] = $app; if (!empty($this->ipAddress)) { $headers['X-Mailin-IP'] = $this->ipAddress; } $toAddresses = array(); $addresses = explode(',', $to); foreach ($addresses as $address) { $extracted = $this->extractEmailToDetails($address); $toAddresses[$extracted['email']] = $extracted['name']; } $data = array( 'to' => $toAddresses, 'from' => array($from), 'subject' => $subject, 'html' => !empty($html) ? $html : $plain, 'headers' => $headers ); if (!empty($attachments)) { $data['attachment'] = $attachments; } if (!empty($replyTo)) { $data['replyTo'] = $replyTo; } if (!empty($cc)) { $ccs = explode(',', $cc); foreach ($ccs as $aCc) { $ccDetails = $this->extractEmailToDetails($aCc); $data['cc'][$ccDetails['email']] = $ccDetails['name']; } } if (!empty($bcc)) { $bccs = explode(',', $bcc); foreach ($bccs as $aBcc) { $bccDetails = $this->extractEmailToDetails($aBcc); $data['bcc'][$bccDetails['email']] = $bccDetails['name']; } } $result = $this->mailin->send_email($data); return $result['code'] === 'success' ? $result['data']['message-id'] : false; } /** * Returns array in the format: * <code> * array( * 'name' => 'John Smith', * 'email' => 'john.smith@email.com' * ); * </code> * * @param $to * @return array */ protected function extractEmailToDetails($to) { $email = $to; $name = ''; if (stripos($to, '<') !== false) { $parts = explode('<', $to); $name = $parts[0]; preg_match('/\\<(.*?)\\>/', $to, $matches); if (!empty($matches)) { $email = $matches[1]; } } return array( 'name' => $name, 'email' => $email ); } } |