Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Access-Control-Allow-Origin: *');
- $text = ' Откуда: ' . strip_tags($_POST['sendFrom']) . "<br>"
- . ' Имя: ' . strip_tags($_POST['firstName']) . "<br>"
- . ' Фамилия: ' . strip_tags($_POST['lastName']) . "<br>"
- . ' Телефон: ' . strip_tags($_POST['phone']) . "<br>"
- . ' e-mail: ' . strip_tags($_POST['email']) . "<br>"
- . ' Компания: ' . strip_tags($_POST['company']) . "<br>"
- . ' Комментарии: ' . strip_tags($_POST['comments']);
- require_once "./phpMailer/PHPMailerAutoload.php";
- if (!preg_match("/^(?:8(?:(?:21|22|23|24|51|52|53|54|55)|(?:15\d\d))?|\+?7)?(?:(?:3[04589]|4[012789]|8[^89\D]|9\d)\d)?\d{7}$/", $_POST['phone'])) {
- $exceptionValidate = array(
- 'status' => false,
- 'error' => 'phone',
- 'message' => 'Invalid phone',
- );
- } elseif ((filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) == false) {
- $exceptionValidate = array(
- 'status' => false,
- 'error' => 'email',
- 'message' => 'Invalid email',
- );
- }
- //Create a new PHPMailer instance
- $mail = new PHPMailer;
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- $mail->Username = 'info.keolaint@gmail.com'; // SMTP username
- $mail->Password = 'keolaint.com'; // SMTP password
- $mail->CharSet = "UTF-8";
- $mail->setFrom('info.keolaint@gmail.com');
- $base = basename($_FILES['resume']['name']);
- $extension = substr($base, strlen($base) - 4, strlen($base));
- $baseFileTwo = basename($_FILES['coverLetter']['name']);
- $extensionFileTwo = substr($baseFileTwo, strlen($baseFileTwo) - 4, strlen($baseFileTwo));
- if($base == "" && $baseFileTwo == "" ){
- //$mail->addAddress('sales@keola.global'); // Add a recipient
- $mail->addAddress('vladislav91@mail.ru'); // Add a recipient
- }else{
- //$mail->addAddress('info@keola.global'); // Add a recipient
- $mail->addAddress('vladislav91@mail.ru'); // Add a recipient
- }
- $allowed_extensions = array("docx",".png",".doc", ".pdf");
- if ( !empty($_FILES['resume']['name'])) {
- if(in_array($extension, $allowed_extensions)){
- $mail->addAttachment($_FILES['resume']['tmp_name'],
- $_FILES['resume']['name']);
- }
- else{
- $exceptionValidate = array(
- 'status' => false,
- 'error' => 'resume',
- 'message' => ' File type not allowed',
- );
- };
- }
- if ( !empty($_FILES['coverLetter']['name'])) {
- if (in_array($extensionFileTwo, $allowed_extensions)) {
- $mail->addAttachment($_FILES['coverLetter']['tmp_name'],
- $_FILES['coverLetter']['name']);
- } else {
- $exceptionValidate = array(
- 'status' => false,
- 'error' => 'coverLetter',
- 'message' => ' File type not allowed',
- );
- };
- }
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Here is the subject';
- $mail->Body = $text;
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- if (!empty($exceptionValidate)) {
- $showresult = $exceptionValidate;
- } else {
- if (!$mail->send()) {
- $showresult = array(
- 'status' => false,
- 'error' => '',
- 'message' => "Email not sent: " . $mail->ErrorInfo,
- );
- } else {
- $showresult = array(
- 'status' => true,
- 'error' => 'SUCCESS',
- 'message' => '',
- );
- }
- }
- header('Content-Type: application/json');
- echo json_encode($showresult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement