public function Mailer::sendMail in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Mail/Mailer.php \Drupal\simplenews\Mail\Mailer::sendMail()
 - 3.x src/Mail/Mailer.php \Drupal\simplenews\Mail\Mailer::sendMail()
 
Send a node to an email address.
Parameters
\Drupal\simplenews\Mail\MailInterface $mail: The mail object.
Return value
bool TRUE if the email was successfully delivered; otherwise FALSE.
Overrides MailerInterface::sendMail
2 calls to Mailer::sendMail()
- Mailer::sendSpool in src/
Mail/ Mailer.php  - Send simplenews newsletters from the spool.
 - Mailer::sendTest in src/
Mail/ Mailer.php  - Send test version of newsletter.
 
File
- src/
Mail/ Mailer.php, line 309  
Class
- Mailer
 - Default Mailer.
 
Namespace
Drupal\simplenews\MailCode
public function sendMail(MailInterface $mail) {
  $params['simplenews_mail'] = $mail;
  // Send mail.
  try {
    $message = $this->mailManager
      ->mail('simplenews', $mail
      ->getKey(), $mail
      ->getRecipient(), $mail
      ->getLanguage(), $params, $mail
      ->getFromFormatted());
    // Log sent result in watchdog.
    if ($this->config
      ->get('mail.debug')) {
      if ($message['result']) {
        $this->logger
          ->debug('Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to', array(
          '%type' => $mail
            ->getKey(),
          '%to' => $message['to'],
          '%subject' => $message['subject'],
        ));
      }
      else {
        $this->logger
          ->error('Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to', array(
          '%type' => $mail
            ->getKey(),
          '%to' => $message['to'],
          '%subject' => $message['subject'],
        ));
      }
    }
    // Build array of sent results for spool table and reporting.
    if ($message['result']) {
      $result = array(
        'status' => SpoolStorageInterface::STATUS_DONE,
        'error' => FALSE,
      );
    }
    else {
      // This error may be caused by faulty mailserver configuration or overload.
      // Mark "pending" to keep trying.
      $result = array(
        'status' => SpoolStorageInterface::STATUS_PENDING,
        'error' => TRUE,
      );
    }
  } catch (SkipMailException $e) {
    $result = array(
      'status' => SpoolStorageInterface::STATUS_SKIPPED,
      'error' => FALSE,
    );
  }
  return $result;
}