Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3.  
  4.  
  5. $text = ' Откуда: ' . strip_tags($_POST['sendFrom']) . "<br>"
  6. . ' Имя: ' . strip_tags($_POST['firstName']) . "<br>"
  7. . ' Фамилия: ' . strip_tags($_POST['lastName']) . "<br>"
  8. . ' Телефон: ' . strip_tags($_POST['phone']) . "<br>"
  9. . ' e-mail: ' . strip_tags($_POST['email']) . "<br>"
  10. . ' Компания: ' . strip_tags($_POST['company']) . "<br>"
  11. . ' Комментарии: ' . strip_tags($_POST['comments']);
  12.  
  13. require_once "./phpMailer/PHPMailerAutoload.php";
  14.  
  15. 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'])) {
  16. $exceptionValidate = array(
  17. 'status' => false,
  18. 'error' => 'phone',
  19. 'message' => 'Invalid phone',
  20. );
  21. } elseif ((filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) == false) {
  22. $exceptionValidate = array(
  23. 'status' => false,
  24. 'error' => 'email',
  25. 'message' => 'Invalid email',
  26. );
  27. }
  28.  
  29. //Create a new PHPMailer instance
  30. $mail = new PHPMailer;
  31. //Tell PHPMailer to use SMTP
  32. $mail->isSMTP();
  33. //Enable SMTP debugging
  34. // 0 = off (for production use)
  35. // 1 = client messages
  36. // 2 = client and server messages
  37. $mail->SMTPDebug = 2;
  38. //Ask for HTML-friendly debug output
  39. $mail->Debugoutput = 'html';
  40. //Set the hostname of the mail server
  41. $mail->Host = 'smtp.gmail.com';
  42. // use
  43. // $mail->Host = gethostbyname('smtp.gmail.com');
  44. // if your network does not support SMTP over IPv6
  45. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  46. $mail->Port = 587;
  47. //Set the encryption system to use - ssl (deprecated) or tls
  48. $mail->SMTPSecure = 'tls';
  49. //Whether to use SMTP authentication
  50. $mail->SMTPAuth = true;
  51.  
  52.  
  53. $mail->Username = 'info.keolaint@gmail.com'; // SMTP username
  54. $mail->Password = 'keolaint.com'; // SMTP password
  55.  
  56.  
  57. $mail->CharSet = "UTF-8";
  58.  
  59. $mail->setFrom('info.keolaint@gmail.com');
  60.  
  61.  
  62.  
  63.  
  64. $base = basename($_FILES['resume']['name']);
  65. $extension = substr($base, strlen($base) - 4, strlen($base));
  66. $baseFileTwo = basename($_FILES['coverLetter']['name']);
  67. $extensionFileTwo = substr($baseFileTwo, strlen($baseFileTwo) - 4, strlen($baseFileTwo));
  68.  
  69.  
  70. if($base == "" && $baseFileTwo == "" ){
  71. //$mail->addAddress('sales@keola.global'); // Add a recipient
  72. $mail->addAddress('vladislav91@mail.ru'); // Add a recipient
  73.  
  74. }else{
  75. //$mail->addAddress('info@keola.global'); // Add a recipient
  76. $mail->addAddress('vladislav91@mail.ru'); // Add a recipient
  77.  
  78. }
  79.  
  80.  
  81.  
  82. $allowed_extensions = array("docx",".png",".doc", ".pdf");
  83. if ( !empty($_FILES['resume']['name'])) {
  84. if(in_array($extension, $allowed_extensions)){
  85. $mail->addAttachment($_FILES['resume']['tmp_name'],
  86. $_FILES['resume']['name']);
  87. }
  88. else{
  89. $exceptionValidate = array(
  90. 'status' => false,
  91. 'error' => 'resume',
  92. 'message' => ' File type not allowed',
  93. );
  94. };
  95. }
  96. if ( !empty($_FILES['coverLetter']['name'])) {
  97. if (in_array($extensionFileTwo, $allowed_extensions)) {
  98. $mail->addAttachment($_FILES['coverLetter']['tmp_name'],
  99. $_FILES['coverLetter']['name']);
  100. } else {
  101. $exceptionValidate = array(
  102. 'status' => false,
  103. 'error' => 'coverLetter',
  104. 'message' => ' File type not allowed',
  105. );
  106. };
  107. }
  108.  
  109. $mail->isHTML(true); // Set email format to HTML
  110. $mail->Subject = 'Here is the subject';
  111. $mail->Body = $text;
  112. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  113. if (!empty($exceptionValidate)) {
  114. $showresult = $exceptionValidate;
  115. } else {
  116. if (!$mail->send()) {
  117. $showresult = array(
  118. 'status' => false,
  119. 'error' => '',
  120. 'message' => "Email not sent: " . $mail->ErrorInfo,
  121. );
  122.  
  123. } else {
  124. $showresult = array(
  125. 'status' => true,
  126. 'error' => 'SUCCESS',
  127. 'message' => '',
  128. );
  129. }
  130. }
  131.  
  132.  
  133. header('Content-Type: application/json');
  134. echo json_encode($showresult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement