Last active
August 29, 2015 14:23
-
-
Save MikSDigital/83e9f607a50886b57c2d to your computer and use it in GitHub Desktop.
Сниппет использовался на сайте Бюро переводов для отправки данных формы
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
/* chunk */ | |
<h3>Пришел запрос сайта</h3> | |
Имя: [[+name]] | |
<br> | |
Телефон: [[+phone]] | |
<br> | |
EMAIL: [[+email]] | |
<br><br> | |
Текст сообщения : [[+message]] |
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
<?php | |
$message=''; | |
$formFields=array(); | |
$uploaddir = '/data02/htdocs/assets/downloads/'; | |
if (!empty($_FILES['attachment']['name'])){ | |
$attachment = $uploaddir . $_FILES['attachment']['name']; | |
move_uploaded_file($_FILES['attachment']['tmp_name'], $attachment); | |
} | |
//return $attachment; | |
/* $attachment содержит полный путь, включая имя файла для аттача */ | |
/*$message = "Имя :".$_POST['name']." , <br>"."e-mail : ".$_POST['email']. " Телефон : ".$_POST['phone'] ;*/ | |
$formFields=array( | |
'name' => $modx->sanitizeString($_POST['name']), | |
'phone' => $_POST['phone'], | |
'email' => $_POST['email'], | |
'message' => $modx->sanitizeString($_POST['message']) | |
); | |
$message = $modx->getChunk('email', $formFields); | |
$modx->getService('mail', 'mail.modSwiftMailer'); | |
$modx->mail->body($message); | |
$modx->mail->address('to','sa@'); | |
//$modx->mail->address('cc', 'min@'); | |
$modx->mail->address('sender', $formFields['email']); | |
$modx->mail->address('from', $formFields['email']); | |
$modx->mail->bounce('info@'); | |
$modx->mail->subject('From '); | |
if (file_exists($attachment)) | |
{ | |
$modx->mail->attach($attachment); | |
} | |
if (!$modx->mail->send()) { | |
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo); | |
} | |
$modx->log(modX::LOG_LEVEL_ERROR,'Попытка отправки почты , отправитель '.$formFields['email']); | |
$modx->mail->reset(); | |
return true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment