Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Last active August 29, 2015 14:23
Show Gist options
  • Save MikSDigital/83e9f607a50886b57c2d to your computer and use it in GitHub Desktop.
Save MikSDigital/83e9f607a50886b57c2d to your computer and use it in GitHub Desktop.
Сниппет использовался на сайте Бюро переводов для отправки данных формы
/* chunk */
<h3>Пришел запрос сайта</h3>
Имя: [[+name]]
<br>
Телефон: [[+phone]]
<br>
EMAIL: [[+email]]
<br><br>
Текст сообщения : [[+message]]
<?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