W
W
WebforSelf2021-01-26 09:59:34
1C-Bitrix
WebforSelf, 2021-01-26 09:59:34

How to send an email to the admin about the successful addition of the bitrix element?

There is this form

<form action="" method="post" enctype="multipart/form-data" class="form-rew">

       <div class="form-group has-feedback">
      <label class="text-uppercase" for="name-review">ФИО<span class="smt-required-star">*</span></label>
                  <input required type="text" class="form-control" placeholder="ФИО" name="NAME" value="" id="name-review">
            <span class="form-control-feedback glyphicon glyphicon-user"></span> 
            </div>    

  <div class="form-group has-feedback">
      <label class="text-uppercase" for="phone-review">Телефон<span class="smt-required-star">*</span></label>
                  <input required type="text" class="form-control" placeholder="Телефон" name="PHONE" value="" id="phone-review">
            <span class="form-control-feedback glyphicon glyphicon-phone"></span> 
            </div>
            
            <div class="form-group has-feedback">
      <label class="text-uppercase" for="mail-review">E-Mail<span class="smt-required-star">*</span></label>
                  <input required type="text" class="form-control" placeholder="E-mail" name="EMAIL" value="" id="mail-review">
            <span class="form-control-feedback glyphicon glyphicon-envelope"></span> 
            </div>	
            
            <div class="form-group has-feedback">
      <label class="text-uppercase" for="smt-order-form-field-orderform-detail_text">Отзыв</label>
       <textarea required id="text-review" placeholder="Отзыв" class="form-control" cols="30" rows="5" name="REVIEWS"></textarea>
            <span class="form-control-feedback glyphicon glyphicon-chevron-down"></span>            			
    </div>

  <input type="submit" class="btn btn-block smt-btn smt-btn_shadow text-uppercase" value="Отправить" name="OK">
</form>


Which is sent in this way

<?
if($_POST["OK"]){
  if(CModule::IncludeModule("iblock")){	
    if($_POST["NAME"]!="" && $_POST["EMAIL"]!="" && $_POST["REVIEWS"]!="" && $_POST["PHONE"]!=""){
      echo "Спасибо, Ваше сообщение отправлено! В ближайшее время его проверят";
      $el = new CIBlockElement;
      $arLoadProductArray = Array(
        "MODIFIED_BY"    => $USER->GetID(), // элемент изменен текущим пользователем
        "IBLOCK_SECTION_ID" => false,          // элемент лежит в корне раздела
        "IBLOCK_ID"      => 11, // id инфоблока, который вы создали
        "NAME"           => $_POST["NAME"], // имя пользователя будет именем элемента
        "ACTIVE"         => "N",            // убираем активность
        "PREVIEW_TEXT"   => $_POST["REVIEWS"], // отзыв клиента
        "DETAIL_TEXT"    => "E-Mail: " . $_POST["EMAIL"] . "\nТелефон: " . $_POST["PHONE"], // контактные данные клиента
        "PREVIEW_PICTURE" => CFile::MakeFileArray($fileID)
        );
      if($PRODUCT_ID = $el->Add($arLoadProductArray))
        echo "";
      else
        echo "";   
    }else{
      echo "Заполнены не все поля";
    }
  }
}
?>


How can I add a letter to the administrator that a new review has been added?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2021-01-26
@anton99zel

bitrix/php_interface/init.php

AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("mailadmin", "OnAfterIBlockElementAddHandlerLast"));
class mailadmin {
   function OnAfterIBlockElementAddHandlerLast(&$arFields) {
      if ($arFields["IBLOCK_ID"] == 11 && $arFields["RESULT"]>0) {
/* получатели */
$to= "Administrator <[email protected]>" . ", " ; 
/* тема/subject */
$subject = 'Новая запись с #'.$ID.' в инфоблоке';
$subject = '=?utf-8?B?'.base64_encode($subject).'?=';
/* сообщение */
$message = '
<html>
<head>
 <title>Новая запись с # ".$ID." в инфоблоке</title>
</head>
<body>
<p>Какой то текст</p>
</body>
</html>
';
$headers= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: My site <[email protected]>\r\n";
$headers .= "Bcc: [email protected]\r\n";
mail($to, $subject, $message, $headers);
      }
   }
};

Y
Yaroslav Alexandrov, 2021-01-26
@alexyarik

https://dev.1c-bitrix.ru/api_help/iblock/events/on...

//отлавливаете событие
AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("AfterElementAdd", "AfterElementAddSendMail"));
  //получаем админов
   $rsAdmins = CUser::GetList($by = "ID", $order = "ASC", array("GROUPS_ID" => 1));
   //получаем $admin["EMAIL"] и отправляем письмо
    while ($admin = $rsAdmins->Fetch()) {
        CEvent::Send(

J
Jupiter Max, 2021-01-26
@vardoLP

you can use this method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question