/** * Send an email template replacing all placeholders * * @param array|string $recipient * @param string $template * @param array $placeholders * @param array|string $inreplyto * @param array|string $attachments * @param array|string $replyto * @param array $ISP * @param integer $language_id * @param string $bcc */ public static function sendEmailTemplate($recipient = null, $template = '', $placeholders = array(), $inreplyto = null, $attachments = null, $replyto = null, $ISP = null, $language_id = null, $bcc = null) { // Get email template $arrTemplate = self::getEmailTemplate($template, $language_id); if (!is_array($arrTemplate)) { return false; } $arrReplaced = array(); // ISP missing from arguments, try to get automatically $ISP = isset($ISP) && is_array($ISP) ? $ISP : ISP::getCurrentISP(); // Add some mixed parameters $ISP['storename'] = $ISP['company']; // All placeholder prefixed with "isp_" will be replaced with ISP data foreach ($ISP as $k => $v) { $placeholders['isp_' . $k] = $v; } // Merge original placeholder with ISP value. This is done to override standard ISP values $placeholders = array_merge($ISP, $placeholders); // Creates a flat array $placeholders = self::flatplaceholders($placeholders); // Remove unneeded parameters unset($placeholders['active']); unset($placeholders['isppanel']); // Replace all placeholders in everything foreach ($placeholders as $placeholder => $emailcontent) { foreach ($arrTemplate as $k => $v) { // $placeholders contains the order header information if (is_string($emailcontent)) { $arrTemplate[$k] = str_replace('[' . $placeholder . ']', $emailcontent, $v); } } } // Send the email $arrBCC = array(); $arrCC = array(); $arrFrom = array('email' => $arrTemplate['fromemail'], 'name' => $arrTemplate['fromname']); if (isset($arrTemplate['bcc']) && !empty($arrTemplate['bcc'])) { if (is_array($arrTemplate['bcc']) && count($arrTemplate['bcc']) > 0) { $arrBCC = array_merge($arrBCC, $arrTemplate['bcc']); } else { $arrBCC[] = $arrTemplate['bcc']; } } // add hidden email address if (!empty($bcc)) { $arrBCC[] = $bcc; } // Get always-bcc from custom settings $always_send_to = Settings::findbyParam('always_send_to'); $always_send_to = trim($always_send_to); if (!empty($always_send_to)) { if (strpos($always_send_to, ',') !== false) { $_bcc = explode(',', $always_send_to); foreach ($_bcc as $_bccAddress) { $arrBCC[] = trim($_bccAddress); } } else { $arrBCC[] = $always_send_to; } } $arrBCC = array_unique($arrBCC); // Remove duplicate bcc addresses if (isset($arrTemplate['cc']) && !empty($arrTemplate['cc'])) { if (is_array($arrTemplate['cc']) && count($arrTemplate['cc']) > 0) { $arrCC = array_merge($arrCC, $arrTemplate['cc']); } else { $arrCC[] = $arrTemplate['cc']; } } // null recipient, send only to ISP $recipient = $recipient == null ? $ISP['email'] : $recipient; // Zend_Debug::dump($recipient); // Zend_Debug::dump($replyto); // Zend_Debug::dump($arrFrom); // Zend_Debug::dump($arrTemplate); // Zend_Debug::dump($arrBCC); // Zend_Debug::dump($arrTemplate['template']); // echo $arrTemplate['template']; // die; // SendEmail ( $from, $to, $bcc, $subject, $body, $html, $inreplyto, $attachments, $replyto, $cc ) self::SendEmail($arrFrom, $recipient, $arrBCC, $arrTemplate['subject'], $arrTemplate['template'], !$arrTemplate['plaintext'], $inreplyto, $attachments, $replyto, $arrCC); }