A
A
Andrew Sky2015-06-19 11:23:03
PHP
Andrew Sky, 2015-06-19 11:23:03

How to create a form with sending to the mail and writing to the infoblock?

How to create a form in Bitrix that, when sent, will send a letter to the mailbox and write the information sent from the form to the infoblock element?
Form without components, plain, HTML.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrew Sky, 2015-06-19
@Sky161

I did everything like this:

<?require_once($_SERVER['DOCUMENT_ROOT'].'/PHPMailer/class.phpmailer.php');
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

$mail_body = implode('/n', $_POST)

/*запись данных в инфоблок*/ 
$arLoadProductArray = Array( "MODIFIED_BY" => $USER->GetID(),
    "IBLOCK_SECTION_ID" => false,
    "IBLOCK_ID" => 24,
    "NAME" => $_POST['name_organization'],
    "ACTIVE" => "N",
    "DETAIL_TEXT" => $mail_body, 
    ); 
CModule::IncludeModule("iblock"); 
$element = new CIBlockElement; 
if($product_ID = $element->Add($arLoadProductArray)){ 
    
    /*отправка формы*/ 
    $mail = new PHPMailer;
    $mail->From = "[email protected]";
    $mail->FromName = "no-replay";
    $mail->AddAddress('почта куда идут письма');

    $mail->isHTML(true);
    $mail->CharSet = 'UTF-8'; 
    $mail->Subject = 'тема письма'; 
    $mail->Body = $mail_body;

    if($mail->Send()){ 
        echo 'Отправлено';
    }
    echo 'Элемент записан ('.$product_ID.') '; 
}else{ 
    echo "Error: ".$element->LAST_ERROR.' '; 
}

A plugin is used to send emails - https://github.com/PHPMailer/PHPMailer

E
Express777, 2015-06-19
@Express777

This is quite simple if you are satisfied with the standard functionality.
There is a simple component in Bitrix. It is called "the form of adding and editing elements".
joxi.ru/52aNjzZIRedxA0
Connect, configure, in particular, in which infoblock to add an element.
His template, of course, is not so hot. Most likely it will need to be changed. But this is another task.
The first task was completed.
Sending letter.
Copy the standard component /bitrix/components/bitrix/iblock.element.add.form to the folder /bitrix/components/my_components/
I hope you know about the rule never to edit standard components. Edit only copied.
Open the component.php file of the iblock.element.add.form component.
Look for the // add new element comment. This is one of the rarest files in Bitrix where there is a comment. Hooray!
Insert into the condition
joxi.ru/12M7aYNTY1xBrJ
https://dev.1c-bitrix.ru/api_help/main/reference/c...
CEvent::SendImmediate
(
$event,
$lid,
$arFields,
$Duplicate = "Y" ,
$message_id=""
)
If you have a non-standard email template. You will most likely need to create a new mail event type and template. But this is another task.
All. Add elements

A
Alexander, 2015-06-19
Madzhugin @Suntechnic

On the one hand, I will support Express777 , and on the other hand, I do it myself without customizing the component - let it be left alone.
Just intercept the event of adding an element to the infoblock you need and send a notification in the interceptor.

A
Alexey, 2015-06-19
@Desving

All this can be done in the file to which the form is sent, if the $_POST array is available, add it to the infoblock and send the message.
adding to the infoblock
sending a letter,
although sending can be done with a regular mail php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question