Ejemplo n.º 1
0
 /**
  * Composes mail message.
  *
  * @param string $from          The sender email address
  * @param string $to            The email address to send mail to
  * @param string $dir           The directiry there mail parts template located
  * @param array  $customHeaders The headers you want to add/replace to. OPTIONAL
  * @param string $interface     Interface to use for mail OPTIONAL
  * @param string $languageCode  Language code OPTIONAL
  *
  * @return void
  */
 public function compose($from, $to, $dir, array $customHeaders = array(), $interface = \XLite::CUSTOMER_INTERFACE, $languageCode = '')
 {
     static::$composeRunned = true;
     if ('' === $languageCode && \XLite::ADMIN_INTERFACE === $interface && !\XLite::isAdminZone()) {
         $languageCode = \XLite\Core\Config::getInstance()->General->default_admin_language;
     }
     \XLite\Core\Translation::setTmpMailTranslationCode($languageCode);
     // initialize internal properties
     $this->set('from', $from);
     $this->set('to', $to);
     $this->set('customHeaders', $customHeaders);
     $this->set('dir', $dir);
     $subject = $this->compile($this->get('subjectTemplate'), $interface);
     $subject = \XLite\Core\Mailer::getInstance()->populateVariables($subject);
     $this->set('subject', $subject);
     $this->set('body', $this->compile($this->get('layoutTemplate'), $interface));
     $body = $this->get('body');
     $body = \XLite\Core\Mailer::getInstance()->populateVariables($body);
     // find all images and fetch them; replace with cid:...
     $fname = tempnam(LC_DIR_COMPILE, 'mail');
     file_put_contents($fname, $body);
     $this->imageParser = new \XLite\Model\MailImageParser();
     $this->imageParser->webdir = \XLite::getInstance()->getShopURL('', false);
     $this->imageParser->parse($fname);
     $this->set('body', $this->imageParser->result);
     $this->set('images', $this->imageParser->images);
     ob_start();
     // Initialize PHPMailer from configuration variables (it should be done once in a script execution)
     $this->initMailFromConfig();
     // Initialize Mail from inner set of variables.
     $this->initMailFromSet();
     $output = ob_get_contents();
     ob_end_clean();
     if ('' !== $output) {
         \XLite\Logger::getInstance()->log('Mailer echoed: "' . $output . '". Error: ' . $this->mail->ErrorInfo);
     }
     // Check if there is any error during mail composition. Log it.
     if ($this->mail->isError()) {
         \XLite\Logger::getInstance()->log('Compose mail error: ' . $this->mail->ErrorInfo);
     }
     if (file_exists($fname)) {
         unlink($fname);
     }
     \XLite\Core\Translation::setTmpMailTranslationCode('');
     static::$composeRunned = false;
 }