예제 #1
0
 /**
  * Initialize the email message.
  *
  * @throws Exception
  * @return \Pop\Mail\Message
  */
 public function init()
 {
     $msgType = $this->getMessageType();
     if (null === $msgType) {
         throw new Exception('Error: The message body elements are not set.');
     }
     if (count($this->mail->getQueue()) == 0) {
         throw new Exception('Error: There are no recipients for this email.');
     }
     $this->message = null;
     $this->setBoundary();
     switch ($msgType) {
         // If the message contains files, HTML and text.
         case self::TEXT_HTML_FILE:
             $this->mail->setHeaders(array('MIME-Version' => '1.0', 'Content-Type' => 'multipart/mixed; boundary="' . $this->getBoundary() . '"' . $this->eol . "This is a multi-part message in MIME format."));
             $attachments = $this->mail->getAttachments();
             foreach ($attachments as $attachment) {
                 $this->message .= $attachment->build($this->getBoundary(), $this->eol);
             }
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/html; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->html . $this->eol . $this->eol;
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/plain; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->text . $this->eol . $this->eol . '--' . $this->getBoundary() . '--' . $this->eol . $this->eol;
             break;
             // If the message contains files and HTML.
         // If the message contains files and HTML.
         case self::HTML_FILE:
             $this->mail->setHeaders(array('MIME-Version' => '1.0', 'Content-Type' => 'multipart/mixed; boundary="' . $this->getBoundary() . '"' . $this->eol . "This is a multi-part message in MIME format."));
             $attachments = $this->mail->getAttachments();
             foreach ($attachments as $attachment) {
                 $this->message .= $attachment->build($this->getBoundary(), $this->eol);
             }
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/html; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->html . $this->eol . $this->eol . '--' . $this->getBoundary() . '--' . $this->eol . $this->eol;
             break;
             // If the message contains files and text.
         // If the message contains files and text.
         case self::TEXT_FILE:
             $this->mail->setHeaders(array('MIME-Version' => '1.0', 'Content-Type' => 'multipart/mixed; boundary="' . $this->getBoundary() . '"' . $this->eol . "This is a multi-part message in MIME format."));
             $attachments = $this->mail->getAttachments();
             foreach ($attachments as $attachment) {
                 $this->message .= $attachment->build($this->getBoundary(), $this->eol);
             }
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/plain; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->text . $this->eol . $this->eol . '--' . $this->getBoundary() . '--' . $this->eol . $this->eol;
             break;
             // If the message contains HTML and text.
         // If the message contains HTML and text.
         case self::TEXT_HTML:
             $this->mail->setHeaders(array('MIME-Version' => '1.0', 'Content-Type' => 'multipart/alternative; boundary="' . $this->getBoundary() . '"' . $this->eol . "This is a multi-part message in MIME format."));
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/plain; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->text . $this->eol . $this->eol;
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/html; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->html . $this->eol . $this->eol . '--' . $this->getBoundary() . '--' . $this->eol . $this->eol;
             break;
             // If the message contains HTML.
         // If the message contains HTML.
         case self::HTML:
             $this->mail->setHeaders(array('MIME-Version' => '1.0', 'Content-Type' => 'multipart/alternative; boundary="' . $this->getBoundary() . '"' . $this->eol . "This is a multi-part message in MIME format."));
             $this->message .= '--' . $this->getBoundary() . $this->eol . 'Content-type: text/html; charset=' . $this->getCharset() . $this->eol . $this->eol . $this->html . $this->eol . $this->eol . '--' . $this->getBoundary() . '--' . $this->eol . $this->eol;
             break;
             // If the message contains text.
         // If the message contains text.
         case self::TEXT:
             $this->mail->setHeaders(array('Content-Type' => 'text/plain; charset=' . $this->getCharset()));
             $this->message = $this->text . $this->eol;
             break;
             // Else if nothing has been set yet
         // Else if nothing has been set yet
         default:
             $this->message = null;
     }
     return $this;
 }