Commit 48409fab authored by Dylan Donkersgoed's avatar Dylan Donkersgoed Committed by Jakob P
Browse files

Issue #3214643 by Dylan Donkersgoed: "Turn on the SMTP keep alive feature" seems non-functional

parent bf9cd789
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -84,6 +84,13 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
   */
  protected $mimeTypeGuesser;

  /**
   * The SMTP object, stored between calls when keep alive is enabled.
   *
   * @var PHPMailer\PHPMailer\SMTP
   */
  protected $persistentSmtp;

  /**
   * Constructs a SMPTMailSystem object.
   *
@@ -211,8 +218,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
    // Optionally reroute all emails to a single address.
    list($to, $headers) = $this->applyRerouting($to, $headers);

    // Create a new PHPMailer object - autoloaded from registry.
    $mailer = new PHPMailer(TRUE);
    $mailer = $this->getMailer();
    // Use email.validator due to different validation standard by PHPMailer.
    $mailer::$validator = [$this->emailValidator, 'isValid'];

@@ -861,4 +867,25 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
    return [$new_to, $new_headers];
  }

  /**
   * Get (and, if applicable, build) the PHPMailer object.
   *
   * @return \PHPMailer\PHPMailer\PHPMailer
   */
  protected function getMailer() {
    if ($this->smtpConfig->get('smtp_keepalive')) {
      $mailer = new PHPMailer(TRUE);
      if ($this->persistentSmtp) {
        $mailer->setSMTPInstance($this->persistentSmtp);
      }
      else {
        $this->persistentSmtp = $mailer->getSMTPInstance();
      }
      return $mailer;
    }
    else {
      return new PHPMailer(TRUE);
    }
  }

}