<?php
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/pmailer/class.phpmailer.php");
class App_BMailer extends PHPMailer
{
public function __construct() {
$this->CharSet = 'utf-8';
$this->Encoding = 'base64';
}
public function sendTemplate($templateType, $fields) {
$rsMess = CEventMessage::GetList($by="site_id", $order="desc",
array(
"TYPE" => $TEMPLATE_TYPE,
"SITE_ID" => SITE_ID,
"ACTIVE" => "Y",
));
if ($arMess = $rsMess->Fetch()) {
$arSearch = array(
"#DEFAULT_EMAIL_FROM#", //E-Mail адрес по умолчанию (устанавливается в настройках)
"#SITE_NAME#", //Название сайта (устанавливается в настройках)
"#SERVER_NAME#" //URL сервера (устанавливается в настройках)
);
$arReplace = array(
COption::GetOptionString("main", "email_from"),
COption::GetOptionString("main", "site_name"),
COption::GetOptionString("main", "server_name"),
);
$from = str_replace($arSearch, $arReplace, $arMess["EMAIL_TO"]);
$this->From = $from;
$to = str_replace($arSearch, $arReplace, $arMess["EMAIL_TO"]);
$this->AddAddress($to);
$bcc = str_replace($arSearch, $arReplace, $arMess["BCC"]);
if(!empty($bcc)) $this->AddBCC($bcc);
$subj = str_replace($arSearch, $arReplace, $arMess["SUBJECT"]);
$this->Subject = $subj;
$text = str_replace($arSearch, $arReplace, $arMess["MESSAGE"]);
foreach($fields as $key => $value) {
$text = str_replace('#'.$key.'#', $value, $text);
}
$this->Body = $text;
$this->IsHTML(true);
if(array_key_exists('FILES', $fields) && is_array($fields['FILES'])) {
foreach($fields['FILES'] as $value) {
$this->AddAttachment($value);
}
}
return $this->Send();
}
return false;
}
}
|