public function SendInBlueEmail::mail in SendinBlue 8
Same name and namespace in other branches
- 8.2 src/Plugin/Mail/SendInBlueEmail.php \Drupal\sendinblue\Plugin\Mail\SendInBlueEmail::mail()
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().
Parameters
array $message: Message array with at least the following elements:
- id: A unique identifier of the email type. Examples: 'contact_user_copy', 'user_password_reset'.
- to: The mail address or addresses where the message will be sent to. The formatting of this string will be validated with the PHP email validation filter. Some examples:
- subject: Subject of the email to be sent. This must not contain any newline characters, or the mail may not be sent properly. The subject is converted to plain text by the mail plugin manager.
- body: Message to be sent. Accepts both CRLF and LF line-endings. Email bodies must be wrapped. For smart plain text wrapping you can use \Drupal\Core\Mail\MailFormatHelper::wrapMail() .
- headers: Associative array containing all additional mail headers not defined by one of the other parameters. PHP's mail() looks for Cc and Bcc headers and sends the mail to addresses in these headers too.
Return value
bool TRUE if the mail was successfully accepted for delivery, otherwise FALSE.
Overrides MailInterface::mail
File
- src/
Plugin/ Mail/ SendInBlueEmail.php, line 77
Class
- SendInBlueEmail
- Defines the default Drupal mail backend, using PHP's native mail() function.
Namespace
Drupal\sendinblue\Plugin\MailCode
public function mail(array $message) {
try {
$to = [
'email' => $message['to'],
];
$from = [
'email' => $message['from'],
];
$message['reply-to'] = !empty($message['reply-to']) ? $message['reply-to'] : $message['from'];
$replyTo = [
'email' => $message['reply-to'],
];
unset($message['headers']['Content-Type']);
$result = $this->sendinblueManager
->getSendinblueMailin()
->sendEmail($to, $message['subject'], nl2br($message['body']), $message['body'], $from, $replyTo, [], [], [], $message['headers']);
if (empty($result
->getMessageId())) {
$this->loggerFactory
->get('mail')
->error('[SENDINBLUE] - Error sending email (from %from to %to with reply-to %reply).', [
'%from' => $message['from'],
'%to' => $message['to'],
'%reply' => $message['reply-to'] ? $message['reply-to'] : 'not set',
]);
return FALSE;
}
$this->loggerFactory
->get('mail')
->info('[SENDINBLUE] - Sending email %messageId (from %from to %to).', [
'%from' => $message['from'],
'%to' => $message['to'],
'%messageId' => $result
->getMessageId(),
]);
return TRUE;
} catch (\Exception $e) {
$this->loggerFactory
->get('mail')
->error('[SENDINBLUE] - Error sending email (from %from to %to with reply-to %reply) [%error].', [
'%from' => $message['from'],
'%to' => $message['to'],
'%reply' => $message['reply-to'] ? $message['reply-to'] : 'not set',
'%error' => $e
->getMessage(),
]);
return FALSE;
}
}