I
I
IgorRastarov2017-03-10 09:41:37
1C-Bitrix
IgorRastarov, 2017-03-10 09:41:37

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 - название почтового шаблона
        }

Contents of the mail template:
A message was sent to you via the feedback form
E-mail: #AUTHOR_EMAIL#
Message text:
#TEXT#
#BLANK#
The message was generated automatically.
Email and TEXT come to the mail. Blank does not come.
Tell me how to make the file also sent.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2017-03-14
@IgorRastarov

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'])));
  }
}

Fields EMAIL_TO and TEXT - are in my mail template at number 8 and with the name IMAGE_FEEDBACK

D
Danbka, 2017-03-10
@Danbka

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.

T
Taurus, 2019-06-21
@Taurus

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 question

Ask a Question

731 491 924 answers to any question