Answer the question
In order to leave comments, you need to log in
How to send a file using the CEvent::Send method to Bitrix?
Hello. Tell me , please, about sending files in emails to Bitrix via cevent::send
I have a regular feedback component that uses a mail template. I have an infoblock with the BLANK property. This property is of type file. I need to send it in a letter. I write in init.php:
AddEventHandler("iblock", "OnAfterIBlockElementAdd", "OnAfterIBlockElementAddHandler");
function OnAfterIBlockElementAddHandler(&$arFields)
{
if($arFields["IBLOCK_ID"] == 8){ // 8 - это ID инфоблока
$mailFields = array(
"BLANK" => $arFields["PROPERTY_VALUES"]["98"], //BLANK - это свойство 8 инфоблока типа файл, 98 - его ID
);
echo CEvent::Send("PLAN_FEEDBACK", 's1', $mailFields); //PLAN_FEEDBACK - название почтового шаблона
}
Answer the question
In order to leave comments, you need to log in
Most likely the problem is that you don't have the EMAIL_TO field in your handler, but most likely it does in the mail template. I also recently encountered a similar problem. I did not use any standard Bitrix components. Plain html form. Here is my code, maybe it will help you.
CModule::IncludeModule('iblock');
$arSelect = Array("NAME", "ID", "PROPERTY_IMAGE");
$arFilter = Array("IBLOCK_ID"=>15, "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array(), $arSelect);
while($ob = $res->GetNextElement())
{
$arFields = $ob->GetFields();
if (!empty($arFields['PROPERTY_IMAGE_VALUE'])){
$arEventField = array(
"EMAIL_TO" => $_POST['email'],// - здесь email - это <input type="email" name="email" placeholder="E-mail" value="" required>
"TEXT" => $_POST['textarea'],// - здесь textarea - это <input type="text" name="textarea" placeholder="Текст сообщения" value="">
);
$image=CFile::GetPath($arFields['PROPERTY_IMAGE_VALUE']);
CEvent::Send("IMAGE_FEEDBACK", 's1', $arEventField,'Y',8,array(CFile::GetPath($arFields['PROPERTY_IMAGE_VALUE'])));
}
}
Everything is written in the documentation: https://dev.1c-bitrix.ru/api_help/main/reference/c...
In your case, it will be something like this:
if $arFields["PROPERTY_VALUES"]["98"] stores the file ID.
Working example
CEvent::Send('FORM_ID', 's1',
array(
'NAME' => $arValues['form_text_25'],
'IMG' => '<img src="ПУТЬ К ИЗОБРАЖЕНИЮ">', // выводится в body письма #IMG#, например, https://домен_не_вызывающий_подозрений_с_тз_спама
),
'N',
'',
array($_img) // $_img в данном случае путь к изображению на сервере (добавляется как аттач к письму, можно передавать несколько изображений, как элементы массива
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question