41 public static function send(array $data)
44 if(CACHED_b_event !==
false && $manageCache->read(CACHED_b_event,
"events"))
46 $manageCache->clean(
'events');
50 if(isset($data[
'FILE']))
52 if(is_array($data[
'FILE']))
53 $fileList = $data[
'FILE'];
59 foreach ($fileList as $file)
62 if (is_numeric($file) && \CFile::GetFileArray($file))
64 $attachment[
'FILE_ID'] = $file;
65 $attachment[
'IS_FILE_COPIED'] =
'N';
69 $fileArray = \CFile::MakeFileArray($file);
70 $fileArray[
'MODULE_ID'] =
'main';
72 $attachment[
'FILE'] = $fileArray;
73 $attachment[
'IS_FILE_COPIED'] =
'Y';
75 $attachments[] = $attachment;
80 $connection->startTransaction();
82 $result = MailInternal\EventTable::add($data);
84 if ($result->isSuccess())
86 $id = $result->getId();
88 foreach ($attachments as $file)
92 'IS_FILE_COPIED' => $file[
'IS_FILE_COPIED'],
93 'FILE_ID' => $file[
'FILE_ID'] ??
null,
96 if ($attachment[
'IS_FILE_COPIED'] ==
'Y')
98 $attachment[
'FILE_ID'] = \CFile::SaveFile($file[
'FILE'],
'main');
101 MailInternal\EventAttachmentTable::add($attachment);
105 $connection->commitTransaction();
119 if(!isset($arEvent[
'FIELDS']) && isset($arEvent[
'C_FIELDS']))
120 $arEvent[
'FIELDS'] = $arEvent[
'C_FIELDS'];
122 if(!is_array($arEvent[
'FIELDS']))
125 $flag = static::SEND_RESULT_TEMPLATE_NOT_FOUND;
135 if(array_key_exists(
'TRACK_READ', $arEvent))
136 $trackRead = $arEvent[
'TRACK_READ'];
137 if(array_key_exists(
'TRACK_CLICK', $arEvent))
138 $trackClick = $arEvent[
'TRACK_CLICK'];
140 $arSites = explode(
",", $arEvent[
"LID"]);
151 static $sites = array();
152 $infoSite = reset($arSites);
154 if(!isset($sites[$infoSite]))
156 $siteDb = Main\SiteTable::getList(array(
157 'select' => array(
'SERVER_NAME',
'CULTURE_CHARSET'=>
'CULTURE.CHARSET'),
158 'filter' => array(
'=LID' => $infoSite)
160 $sites[$infoSite] = $siteDb->fetch();
163 if(is_array($sites[$infoSite]))
165 $charset = $sites[$infoSite][
'CULTURE_CHARSET'];
166 $serverName = $sites[$infoSite][
'SERVER_NAME'];
175 $arEventMessageFilter = array();
176 $MESSAGE_ID = intval($arEvent[
"MESSAGE_ID"]);
179 $eventMessageDb = MailInternal\EventMessageTable::getById($MESSAGE_ID);
180 if($eventMessageDb->Fetch())
182 $arEventMessageFilter[
'=ID'] = $MESSAGE_ID;
183 $arEventMessageFilter[
'=ACTIVE'] =
'Y';
186 if(empty($arEventMessageFilter))
188 $arEventMessageFilter = array(
190 '=EVENT_NAME' => $arEvent[
"EVENT_NAME"],
191 '=EVENT_MESSAGE_SITE.SITE_ID' => $arSites,
194 if($arEvent[
"LANGUAGE_ID"] <>
'')
196 $arEventMessageFilter[] = array(
198 array(
"=LANGUAGE_ID" => $arEvent[
"LANGUAGE_ID"]),
199 array(
"=LANGUAGE_ID" =>
null),
205 $messageDb = MailInternal\EventMessageTable::getList(array(
206 'select' => array(
'ID'),
207 'filter' => $arEventMessageFilter,
208 'group' => array(
'ID')
211 while($arMessage = $messageDb->fetch())
213 $eventMessage = MailInternal\EventMessageTable::getRowById($arMessage[
'ID']);
215 $eventMessage[
'FILE'] = array();
216 $attachmentDb = MailInternal\EventMessageAttachmentTable::getList(array(
217 'select' => array(
'FILE_ID'),
218 'filter' => array(
'=EVENT_MESSAGE_ID' => $arMessage[
'ID']),
220 while($arAttachmentDb = $attachmentDb->fetch())
222 $eventMessage[
'FILE'][] = $arAttachmentDb[
'FILE_ID'];
226 $arFields = $arEvent[
'FIELDS'];
228 foreach (GetModuleEvents(
"main",
"OnBeforeEventSend",
true) as $event)
230 if(ExecuteModuleEventEx($event, array(&$arFields, &$eventMessage, $context, &$arResult)) ===
false)
237 $arMessageParams = array(
239 'FIELDS' => $arFields,
240 'MESSAGE' => $eventMessage,
242 'CHARSET' => $charset,
244 $message = EventMessageCompiler::createInstance($arMessageParams);
251 $arResult[
"Was"] =
true;
252 $arResult[
"Fail"] =
true;
257 $result = Main\Mail\Mail::send(array(
258 'TO' => $message->getMailTo(),
259 'SUBJECT' => $message->getMailSubject(),
260 'BODY' => $message->getMailBody(),
261 'HEADER' => $message->getMailHeaders(),
262 'CHARSET' => $message->getMailCharset(),
263 'CONTENT_TYPE' => $message->getMailContentType(),
264 'MESSAGE_ID' => $message->getMailId(),
265 'ATTACHMENT' => $message->getMailAttachment(),
266 'TRACK_READ' => $trackRead,
267 'TRACK_CLICK' => $trackClick,
268 'LINK_PROTOCOL' =>
Config\Option::get(
"main",
"mail_link_protocol",
''),
269 'LINK_DOMAIN' => $serverName,
270 'CONTEXT' => $context,
273 $arResult[
"Success"] =
true;
275 $arResult[
"Fail"] =
true;
277 $arResult[
"Was"] =
true;
282 if($arResult[
"Success"])
284 if($arResult[
"Fail"])
285 $flag = static::SEND_RESULT_PARTLY;
287 $flag = static::SEND_RESULT_SUCCESS;
291 if($arResult[
"Fail"])
292 $flag = static::SEND_RESULT_ERROR;
295 elseif($arResult[
"Skip"])
297 $flag = static::SEND_RESULT_NONE;