예제 #1
0
 /**
  * Send an email with HTML content.
  *
  * @see sendPlain() for sending plaintext emails only.
  * @uses Mailer->sendHTML()
  *
  * @param string $messageID Optional message ID so the message can be identified in bounces etc.
  * @return mixed Success of the sending operation from an MTA perspective. Doesn't actually give any indication if
  * the mail has been delivered to the recipient properly). See Mailer->sendPlain() for return type details.
  */
 public function send($messageID = null)
 {
     Requirements::clear();
     $this->parseVariables();
     if (empty($this->from)) {
         $this->from = Email::config()->admin_email;
     }
     $headers = $this->customHeaders;
     if ($messageID) {
         $headers['X-SilverStripeMessageID'] = project() . '.' . $messageID;
     }
     if (project()) {
         $headers['X-SilverStripeSite'] = project();
     }
     $to = $this->to;
     $from = $this->from;
     $subject = $this->subject;
     if ($sendAllTo = $this->config()->send_all_emails_to) {
         $subject .= " [addressed to {$to}";
         $to = $sendAllTo;
         if ($this->cc) {
             $subject .= ", cc to {$this->cc}";
         }
         if ($this->bcc) {
             $subject .= ", bcc to {$this->bcc}";
         }
         $subject .= ']';
         unset($headers['Cc']);
         unset($headers['Bcc']);
     } else {
         if ($this->cc) {
             $headers['Cc'] = $this->cc;
         }
         if ($this->bcc) {
             $headers['Bcc'] = $this->bcc;
         }
     }
     if ($ccAllTo = $this->config()->cc_all_emails_to) {
         if (!empty($headers['Cc']) && trim($headers['Cc'])) {
             $headers['Cc'] .= ', ' . $ccAllTo;
         } else {
             $headers['Cc'] = $ccAllTo;
         }
     }
     if ($bccAllTo = $this->config()->bcc_all_emails_to) {
         if (!empty($headers['Bcc']) && trim($headers['Bcc'])) {
             $headers['Bcc'] .= ', ' . $bccAllTo;
         } else {
             $headers['Bcc'] = $bccAllTo;
         }
     }
     if ($sendAllfrom = $this->config()->send_all_emails_from) {
         if ($from) {
             $subject .= " [from {$from}]";
         }
         $from = $sendAllfrom;
     }
     Requirements::restore();
     return self::mailer()->sendHTML($to, $from, $subject, $this->body, $this->attachments, $headers, $this->plaintext_body);
 }