function simple_mail_queue in Simple Mail 8
Same name and namespace in other branches
- 7 simple_mail.module \simple_mail_queue()
- 2.0.x simple_mail.module \simple_mail_queue()
Queue an email to be sent via the Queue API during cron runs.
Queues an email for sending through Drupal's Queue API, rather than sending immediately. This function is basically a queued version of the nearly- identical function simple_mail_send_email(). Use this function when sending batches of email so the page request is not delayed while waiting for individual messages to be sent.
Parameters
(string) $from: Email sender. Defaults to the system email.
(string) $to: Email receipient.
(string) $subject: Email subject.
(string) $body: Email message body (can be HTML or plaintext).
Return value
bool TRUE if the email was queued, FALSE otherwise.
See also
File
- ./
simple_mail.module, line 94 - Simple Mail module.
Code
function simple_mail_queue($from, $to, $subject, $body) {
$queue_enabled = \Drupal::config('simple_mail.settings')
->get('queue_enabled');
// If the queue is disabled, return FALSE.
if (!$queue_enabled) {
return FALSE;
}
// Queue the email.
$queue = Drupal::queue('simple_mail_queue', TRUE);
$item = array(
'from' => $from,
'to' => $to,
'subject' => $subject,
'body' => $body,
);
$queue
->createItem($item);
return TRUE;
}