Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $json = [];
- if (isset($_POST['user_name'], $_POST['user_phone'], $_POST['user_msg']))
- {
- $_POST['user_name'] = htmlspecialchars($_POST['user_name']);
- $_POST['user_phone'] = htmlspecialchars($_POST['user_phone']);
- $_POST['user_msg'] = htmlspecialchars($_POST['user_msg']);
- $lenName = mb_strlen($_POST['user_name']);
- $lenPhone = mb_strlen($_POST['user_phone']);
- $lenMsg = mb_strlen($_POST['user_msg']);
- if ($lenName > 0 && $lenName <= 40 && $lenPhone > 0 && $lenPhone <= 255 && $lenMsg > 0)
- {
- require __DIR__ . '/vendor/autoload.php';
- $smtpHost = 'smtp.yandex.com';
- $smtpPort = 465;
- $security = 'SSL';
- $smtpUsername = 'mob-pro-test@yandex.ru';
- $smtpPassword = 'mob-pro1234';
- $transport = (new Swift_SmtpTransport($smtpHost, $smtpPort, $security))
- ->setUsername($smtpUsername)
- ->setPassword($smtpPassword);
- $mailer = new Swift_Mailer($transport);
- $from = [$smtpUsername => $_POST['user_name']];
- $to = 'yury_borisov@rambler.ru';
- $subject = 'Feedback Mobile Professionals';
- $body = 'Имя: ' . $_POST['user_name'] . "\nТелефон или почта: " . $_POST['user_phone'] . "\nСообщение: " . $_POST['user_msg'];
- $message = (new Swift_Message($subject))
- ->setFrom($from)
- ->setTo([$to])
- ->setBody($body);
- if (isset($_FILES['file']))
- $message->attach(Swift_Attachment::fromPath($_FILES['file']['tmp_name'])->setFilename($_FILES['file']['name']));
- $result = $mailer->send($message);
- $json['status'] = true;
- }
- else
- {
- $json['status'] = false;
- $json['message'] = 'field in the request failed validation';
- }
- }
- else
- {
- $json['status'] = false;
- $json['message'] = 'invalid parameters';
- }
- header("Access-Control-Allow-Origin: *");
- echo json_encode($json);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement