N
N
Nikolay Matyushkin2018-07-24 10:27:09
1C-Bitrix
Nikolay Matyushkin, 2018-07-24 10:27:09

A letter from the feedback comes, but there is no attachment, what's wrong?

Hello.
Purpose: to add to the standard functionality of the feedback component the ability to send attachments (with a weight limit of no more than 10mb).
What I did: copied the Bitrix feedback component to another folder, started changing it. Here is a code snippet below, where I added saving the file first, and then sending it. But the attachment does not come, what's wrong? Tell me please.

if($arParams["USE_CAPTCHA"] == "Y")
{
$captcha_code = $_POST["captcha_sid"];
$captcha_word = $_POST["captcha_word"];
$cpt = new CCaptcha();
$captchaPass = COption::GetOptionString("main", "captcha_password", "");
if (strlen($captcha_word) > 0 && strlen($captcha_code) > 0)
{
if (!$cpt->CheckCodeCrypt($captcha_word, $captcha_code, $captchaPass))
$arResult["ERROR_MESSAGE"][] = GetMessage("MF_CAPTCHA_WRONG");
}
else
$arResult["ERROR_MESSAGE"][] = GetMessage("MF_CAPTHCA_EMPTY");

}
if($_FILES['file']['size'] < 10485760)
{
$filePath = $_FILES['file']['tmp_name'];
$fileId = CFile::SaveFile(
  array(
    "name" => $_FILES['file']['name'],
    "size" => $_FILES['file']['size'],
    "tmp_name" => $filePath,
    "old_file" => "0",
    "del" => "N",
    "MODULE_ID" => "",
    "description" => "",
  ),
  'mails',
  false,
  false
);
}
else
{
$arResult["ERROR_MESSAGE"][] = GetMessage("MF_SIZ_IMG");
}

if(empty($arResult["ERROR_MESSAGE"]))
{


$arFields = Array(
"AUTHOR" => $_POST["user_name"],
"AUTHOR_EMAIL" => $_POST["user_email"],
"EMAIL_TO" => $arParams["EMAIL_TO"],
"TOPIC" => $_POST["user_topic"],
"TITLE_MESSAGE" => $title_message_assess." ".$title_message,
"TEXT" => $_POST["MESSAGE"],
);
if(!empty($arParams["EVENT_MESSAGE_ID"]))
{
foreach($arParams["EVENT_MESSAGE_ID"] as $v)
if(IntVal($v) > 0)
CEvent::Send($arParams["EVENT_NAME"], SITE_ID, $arFields, "N", IntVal($v), $fileId);
CFile::Delete($fileId);
}
else
CEvent::Send($arParams["EVENT_NAME"], SITE_ID, $arFields, $fileId);
$_SESSION["MF_NAME"] = htmlspecialcharsbx($_POST["user_name"]);
$_SESSION["MF_EMAIL"] = htmlspecialcharsbx($_POST["user_email"]);
LocalRedirect($APPLICATION->GetCurPageParam("success=".$arResult["PARAMS_HASH"], Array("success")));
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Aleinikov, 2018-07-24
@va_rabbit

It's hard to understand from this code snippet, you need to see the whole code.
The first thing that catches your eye:

else
CEvent::Send($arParams["EVENT_NAME"], SITE_ID, $arFields, $fileId);

You don’t have all the parameters here, i.e. if you are attaching a file, then specify all the parameters sequentially.
As here:
The order can be viewed here .
If it does not help, then on each branch (if / else) and assignment, see what is in $fileId, i.e.
var_dump($fileId);
//или
print_r($fileId);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question