Advertisement
Guest User

Untitled

a guest
Aug 28th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. <?php
  2.  
  3. $json = [];
  4. if (isset($_POST['user_name'], $_POST['user_phone'], $_POST['user_msg']))
  5. {
  6.     $_POST['user_name'] = htmlspecialchars($_POST['user_name']);
  7.     $_POST['user_phone'] = htmlspecialchars($_POST['user_phone']);
  8.     $_POST['user_msg'] = htmlspecialchars($_POST['user_msg']);
  9.  
  10.     $lenName = mb_strlen($_POST['user_name']);
  11.     $lenPhone = mb_strlen($_POST['user_phone']);
  12.     $lenMsg = mb_strlen($_POST['user_msg']);
  13.  
  14.     if ($lenName > 0 && $lenName <= 40 && $lenPhone > 0 && $lenPhone <= 255 && $lenMsg > 0)
  15.     {
  16.         require __DIR__ . '/vendor/autoload.php';
  17.         $smtpHost = 'smtp.yandex.com';
  18.         $smtpPort = 465;
  19.         $security = 'SSL';
  20.         $smtpUsername = 'mob-pro-test@yandex.ru';
  21.         $smtpPassword = 'mob-pro1234';
  22.         $transport = (new Swift_SmtpTransport($smtpHost, $smtpPort, $security))
  23.             ->setUsername($smtpUsername)
  24.             ->setPassword($smtpPassword);
  25.         $mailer = new Swift_Mailer($transport);
  26.         $from = [$smtpUsername => $_POST['user_name']];
  27.         $to = 'yury_borisov@rambler.ru';
  28.         $subject = 'Feedback Mobile Professionals';
  29.         $body = 'Имя: ' . $_POST['user_name'] . "\nТелефон или почта: " . $_POST['user_phone'] . "\nСообщение: " . $_POST['user_msg'];
  30.         $message = (new Swift_Message($subject))
  31.             ->setFrom($from)
  32.             ->setTo([$to])
  33.             ->setBody($body);
  34.         if (isset($_FILES['file']))
  35.             $message->attach(Swift_Attachment::fromPath($_FILES['file']['tmp_name'])->setFilename($_FILES['file']['name']));
  36.         $result = $mailer->send($message);
  37.         $json['status'] = true;
  38.     }
  39.     else
  40.     {
  41.         $json['status'] = false;
  42.         $json['message'] = 'field in the request failed validation';
  43.     }
  44. }
  45. else
  46. {
  47.     $json['status'] = false;
  48.     $json['message'] = 'invalid parameters';
  49. }
  50.  
  51. header("Access-Control-Allow-Origin: *");
  52. echo json_encode($json);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement