[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/adapter/ -> PhabricatorMailImplementationPHPMailerAdapter.php (source)

   1  <?php
   2  
   3  final class PhabricatorMailImplementationPHPMailerAdapter
   4    extends PhabricatorMailImplementationAdapter {
   5  
   6    /**
   7     * @phutil-external-symbol class PHPMailer
   8     */
   9    public function __construct() {
  10      $root = phutil_get_library_root('phabricator');
  11      $root = dirname($root);
  12      require_once $root.'/externals/phpmailer/class.phpmailer.php';
  13      $this->mailer = new PHPMailer($use_exceptions = true);
  14      $this->mailer->CharSet = 'utf-8';
  15  
  16      $encoding = PhabricatorEnv::getEnvConfig('phpmailer.smtp-encoding', '8bit');
  17      $this->mailer->Encoding = $encoding;
  18  
  19      // By default, PHPMailer sends one mail per recipient. We handle
  20      // multiplexing higher in the stack, so tell it to send mail exactly
  21      // like we ask.
  22      $this->mailer->SingleTo = false;
  23  
  24      $mailer = PhabricatorEnv::getEnvConfig('phpmailer.mailer');
  25      if ($mailer == 'smtp') {
  26        $this->mailer->IsSMTP();
  27        $this->mailer->Host = PhabricatorEnv::getEnvConfig('phpmailer.smtp-host');
  28        $this->mailer->Port = PhabricatorEnv::getEnvConfig('phpmailer.smtp-port');
  29        $user = PhabricatorEnv::getEnvConfig('phpmailer.smtp-user');
  30        if ($user) {
  31          $this->mailer->SMTPAuth = true;
  32          $this->mailer->Username = $user;
  33          $this->mailer->Password =
  34            PhabricatorEnv::getEnvConfig('phpmailer.smtp-password');
  35        }
  36  
  37        $protocol = PhabricatorEnv::getEnvConfig('phpmailer.smtp-protocol');
  38        if ($protocol) {
  39          $protocol = phutil_utf8_strtolower($protocol);
  40          $this->mailer->SMTPSecure = $protocol;
  41        }
  42      } else if ($mailer == 'sendmail') {
  43        $this->mailer->IsSendmail();
  44      } else {
  45        // Do nothing, by default PHPMailer send message using PHP mail()
  46        // function.
  47      }
  48    }
  49  
  50    public function supportsMessageIDHeader() {
  51      return true;
  52    }
  53  
  54    public function setFrom($email, $name = '') {
  55      $this->mailer->SetFrom($email, $name, $crazy_side_effects = false);
  56      return $this;
  57    }
  58  
  59    public function addReplyTo($email, $name = '') {
  60      $this->mailer->AddReplyTo($email, $name);
  61      return $this;
  62    }
  63  
  64    public function addTos(array $emails) {
  65      foreach ($emails as $email) {
  66        $this->mailer->AddAddress($email);
  67      }
  68      return $this;
  69    }
  70  
  71    public function addCCs(array $emails) {
  72      foreach ($emails as $email) {
  73        $this->mailer->AddCC($email);
  74      }
  75      return $this;
  76    }
  77  
  78    public function addAttachment($data, $filename, $mimetype) {
  79      $this->mailer->AddStringAttachment(
  80        $data,
  81        $filename,
  82        'base64',
  83        $mimetype);
  84      return $this;
  85    }
  86  
  87    public function addHeader($header_name, $header_value) {
  88      if (strtolower($header_name) == 'message-id') {
  89        $this->mailer->MessageID = $header_value;
  90      } else {
  91        $this->mailer->AddCustomHeader($header_name.': '.$header_value);
  92      }
  93      return $this;
  94    }
  95  
  96    public function setBody($body) {
  97      $this->mailer->IsHTML(false);
  98      $this->mailer->Body = $body;
  99      return $this;
 100    }
 101  
 102    public function setHTMLBody($html_body) {
 103      $this->mailer->IsHTML(true);
 104      $this->mailer->Body = $html_body;
 105      return $this;
 106    }
 107  
 108    public function setSubject($subject) {
 109      $this->mailer->Subject = $subject;
 110      return $this;
 111    }
 112  
 113    public function hasValidRecipients() {
 114      return true;
 115    }
 116  
 117    public function send() {
 118      return $this->mailer->Send();
 119    }
 120  
 121  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1