Created
October 14, 2013 08:31
-
-
Save sartas/6972683 to your computer and use it in GitHub Desktop.
bitrix attache files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| require('phpmailer.php'); | |
| require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); | |
| $a = $b = null; | |
| $res = CEventMessage::GetList($a, $b, array('EVENT_NAME' => 'USER_QUESTION')); | |
| $mess = $res->Fetch(); | |
| $data = array( | |
| 'result' => '-1', | |
| 'error' => false, | |
| 'message' => '', | |
| ); | |
| if (isset($_POST['quest'])) | |
| { | |
| $post = $_POST['quest']; | |
| // if (!isset($post['username']) || trim($post['username']) == '') | |
| // { | |
| // $data['error'] = true; | |
| // $data['message'] .= 'Не заполнено поле «Имя»<br/>'; | |
| // } | |
| // if (!isset($post['userphone']) || trim($post['userphone']) == '') | |
| // { | |
| // $data['error'] = true; | |
| // $data['message'] .= 'Не заполнено поле «Телефон»<br/>'; | |
| // } | |
| if ($data['error'] !== true) | |
| { | |
| $arFields = array( | |
| "USERNAME" => clear($post["Name"]), | |
| "PHONE" => clear($post["Phone"]), | |
| "MAIL" => clear($post["Mail"]), | |
| "COMMENT" => clear($post["Comment"]), | |
| ); | |
| $site_fields = CallEvent::GetSiteFieldsArray($mess['SITE_ID']); | |
| $arFields = $arFields + $site_fields; | |
| $mess['EMAIL_FROM'] = CAllEvent::ReplaceTemplate($mess["EMAIL_FROM"], $arFields); | |
| $mess['EMAIL_TO'] = CAllEvent::ReplaceTemplate($mess["EMAIL_TO"], $arFields); | |
| $mess['MESSAGE'] = CAllEvent::ReplaceTemplate($mess["MESSAGE"], $arFields); | |
| $mess['SUBJECT'] = CAllEvent::ReplaceTemplate($mess["SUBJECT"], $arFields); | |
| // print_r($mess); | |
| // exit; | |
| $mail = new PHPMailer(true); | |
| try | |
| { | |
| $mail->SetFrom($mess['EMAIL_FROM']); | |
| $mail->AddAddress($mess['EMAIL_TO']); | |
| $mail->Subject = $mess['SUBJECT']; | |
| $mail->IsHTML(); | |
| $mail->CharSet = "UTF-8"; | |
| $mail->Body = $mess['MESSAGE']; | |
| // print_r($_FILES); | |
| $files_to_delete = array(); | |
| if (isset($_FILES['userFiles'])) | |
| { | |
| foreach ($_FILES['userFiles']['name'] as $key => $name) | |
| { | |
| if ($name) | |
| { | |
| // var_dump(is_file($_FILES['userFiles']['tmp_name'][$key])); | |
| $new_path = $_SERVER['DOCUMENT_ROOT'] . '/ajax/files/' . $name; | |
| $files_to_delete[] = $new_path; | |
| move_uploaded_file($_FILES['userFiles']['tmp_name'][$key], $_SERVER['DOCUMENT_ROOT'] . '/ajax/files/' . $name); | |
| $mail->AddAttachment($new_path, $name); | |
| } | |
| } | |
| } | |
| $mail->Send(); | |
| foreach ($files_to_delete as $file) | |
| { | |
| unlink($file); | |
| } | |
| } | |
| catch (phpmailerException $e) | |
| { | |
| echo $e->errorMessage(); //Pretty error messages from PHPMailer | |
| } | |
| header('Location: ' . substr($_SERVER['HTTP_REFERER'], 0, strpos($_SERVER['HTTP_REFERER'], '?')) . '?question_ok'); | |
| // print_r($mess); | |
| exit; | |
| } | |
| } | |
| else | |
| { | |
| $data['message'] = 'Не заполнены обязательные поля.'; | |
| } | |
| function clear($str) | |
| { | |
| return htmlspecialchars(trim($str), ENT_QUOTES); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment