You are here

function _smtp_mailer_send in SMTP Authentication Support 8

Helper function to send mails.

Parameters

array $variables: Variables to send email.

Return value

bool True if email was sent. False otherwise.

2 calls to _smtp_mailer_send()
SMTPMailSystem::smtpMailerSend in src/Plugin/Mail/SMTPMailSystem.php
Wrapper around global static call to increase testability.
smtp_send_queue_runner in ./smtp.module
SMTP queue runner function.

File

./smtp.module, line 80
Enables Drupal to send e-mail directly to an SMTP server.

Code

function _smtp_mailer_send(array $variables) {
  $smtp_config = \Drupal::config('smtp.settings');
  $mailer = $variables['mailer'];
  $to = $variables['to'];
  $from = $variables['from'];
  $logger = \Drupal::logger('smtp');

  // Let the people know what is going on.
  $logger
    ->info('Sending mail to: @to', [
    '@to' => $to,
  ]);

  // Try to send e-mail. If it fails, set watchdog entry.
  try {
    $mailer
      ->Send();
  } catch (Exception $e) {
    $logger
      ->error('Error sending e-mail from @from to @to: @error_message', [
      '@from' => $from,
      '@to' => $to,
      '@error_message' => $mailer->ErrorInfo,
    ]);
    return FALSE;
  }
  if (!$smtp_config
    ->get('smtp_keepalive')) {
    $mailer
      ->SmtpClose();
  }
  return TRUE;
}