/** * Adds a new part to the message, and can add in signature * * @param string $body * @param string $contentType * @param bool $signature * @return bool */ public function addPart($body, $contentType = null, $signature = true) { if ($signature) { $body = $this->appendSignature($body, $contentType); } $this->message->addPart($body, $contentType); }
/** * Create a Dublin Core record from a row. * * @param array $row * @return void * @access private * @since 10/4/07 */ private function createDcRecord($row) { $dc = $this->repository->dcRecordStructure; $this->dcRecord = new SimpleTableRecord($this->repository->idMgr, $dc); foreach ($this->config['dc_mapping'] as $dcField => $mapping) { $partStructure = $dc->getPartStructure($this->repository->idMgr->getId($dcField)); $value = ''; foreach ($mapping as $component) { if (preg_match('/^[\'"](.+)[\'"]$/i', $component, $matches)) { $value .= $matches[1]; } else { if (preg_match('/^[a-z_-]+$/i', $component)) { $value .= $row[$component]; } else { throw new ConfigurationErrorException('Unknown DC mapping component, "' . $component . '".'); } } } $this->dcRecord->addPart(new SimpleTablePart($partStructure, $value, $this->config['encoding'])); } }
/** * Get e-mail addresses from an array, string or unlimited number of arguments and send the e-mail * * Friendly name portions (e.g. Leo <*****@*****.**>) are allowed. * @param mixed * @return boolean */ public function sendTo() { $arrRecipients = $this->compileRecipients(func_get_args()); if (!count($arrRecipients)) { return false; } $this->objMessage->setTo($arrRecipients); $this->objMessage->setCharset($this->strCharset); $this->objMessage->setPriority($this->intPriority); // Default subject if (empty($this->strSubject)) { $this->strSubject = 'No subject'; } $this->objMessage->setSubject($this->strSubject); // HTML e-mail if (!empty($this->strHtml)) { // Embed images if ($this->blnEmbedImages) { if (!strlen($this->strImageDir)) { $this->strImageDir = TL_ROOT . '/'; } $arrMatches = array(); preg_match_all('/src="([^"]+\\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $this->strHtml, $arrMatches); $strBase = Environment::getInstance()->base; // Check for internal images foreach (array_unique($arrMatches[1]) as $url) { // Try to remove the base URL $src = str_replace($strBase, '', $url); // Embed the image if the URL is now relative if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src)) { $cid = $this->objMessage->embed(Swift_EmbeddedFile::fromPath($this->strImageDir . $src)); $this->strHtml = str_replace('src="' . $url . '"', 'src="' . $cid . '"', $this->strHtml); } } } $this->objMessage->setBody($this->strHtml, 'text/html'); } // Text content if (!empty($this->strText)) { if (!empty($this->strHtml)) { $this->objMessage->addPart($this->strText, 'text/plain'); } else { $this->objMessage->setBody($this->strText, 'text/plain'); } } // Add the administrator e-mail as default sender if ($this->strSender == '') { list($this->strSenderName, $this->strSender) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']); } // Sender if ($this->strSenderName != '') { $this->objMessage->setFrom(array($this->strSender => $this->strSenderName)); } else { $this->objMessage->setFrom($this->strSender); } // Send e-mail $intSent = self::$objMailer->send($this->objMessage, $this->arrFailures); // Log failures if (!empty($this->arrFailures)) { log_message('E-mail address rejected: ' . implode(', ', $this->arrFailures), $this->strLogFile); } // Return if no e-mails have been sent if ($intSent < 1) { return false; } // Add log entry $strMessage = 'An e-mail has been sent to ' . implode(', ', array_keys($this->objMessage->getTo())); if (count($this->objMessage->getCc()) > 0) { $strMessage .= ', CC to ' . implode(', ', array_keys($this->objMessage->getCc())); } if (count($this->objMessage->getBcc()) > 0) { $strMessage .= ', BCC to ' . implode(', ', array_keys($this->objMessage->getBcc())); } log_message($strMessage, $this->strLogFile); return true; }
/** * Setup the message * * @access public * @param string method * @return object * **/ public function setup($method = NULL) { $this->message = Swift_Message::newInstance(); $this->message->setSubject($this->subject); $is_html = isset($this->html); $is_text = isset($this->text); if ($is_html || $is_text) { if ($is_html) { $this->view["html"] = $this->html; $this->message->setBody($this->view['html'], 'text/html'); } if ($is_text) { $this->view["text"] = $this->text; if ($is_html) { $this->message->addPart($this->view['text'], 'text/plain'); } else { $this->message->setBody($this->view['text'], 'text/plain'); } } } else { // View $template = strtolower(preg_replace('/_/', '/', get_class($this)) . "/{$method}"); $text = View::factory($template); $this->set_data($text); $this->view['text'] = $text->render(); if ($this->type === 'html') { $template = View::factory($template); $this->set_data($template); $this->view['html'] = $this->view['text']; $this->view['text'] = $template->render(); $this->message->setBody($this->view['html'], 'text/html'); $this->message->addPart($this->view['text'], 'text/plain'); } else { $this->message->setBody($this->view['html'], 'text/plain'); } } if ($this->attachments !== null) { if (!is_array($this->attachments)) { $this->attachments = array($this->attachments); } foreach ($this->attachments as $file) { $this->message->attach(Swift_Attachment::fromPath($file)); } } // to if (!is_array($this->to)) { $this->to = array($this->to); } $this->message->setTo($this->to); // cc if ($this->cc !== null) { if (!is_array($this->cc)) { $this->cc = array($this->cc); } $this->message->setCc($this->cc); } // bcc if ($this->bcc !== null) { if (!is_array($this->bcc)) { $this->bcc = array($this->bcc); } $this->message->setBcc($this->bcc); } // from $this->message->setFrom($this->from); return $this; }