Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 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. $mail->isSMTP();
  32. $mail->SMTPDebug = 0;
  33. $mail->Debugoutput = 'html';
  34. $mail->CharSet = "UTF-8";
  35. $mail->Host = 'smtp.gmail.com';
  36. $mail->Port = 587;
  37. $mail->SMTPSecure = 'tls';
  38. $mail->SMTPAuth = true;
  39. $mail->Username = 'info.keolaint@gmail.com';
  40. $mail->Password = 'keolaint.com';
  41. $mail->setFrom('info.keolaint@gmail.com', '');
  42.  
  43. $base = basename($_FILES['resume']['name']);
  44. $extension = substr($base, strlen($base) - 4, strlen($base));
  45. $baseFileTwo = basename($_FILES['coverLetter']['name']);
  46. $extensionFileTwo = substr($baseFileTwo, strlen($baseFileTwo) - 4, strlen($baseFileTwo));
  47.  
  48. if($base == "" && $baseFileTwo == "" ){
  49. //$mail->addAddress('sales@keola.global'); // Add a recipient
  50. $mail->addAddress('vladislav91@mail.ru',''); // Add a recipient
  51.  
  52. }else{
  53. //$mail->addAddress('info@keola.global'); // Add a recipient
  54. $mail->addAddress('vladislav91@mail.ru',''); // Add a recipient
  55. }
  56.  
  57. $allowed_extensions = array("docx",".png",".doc", ".pdf");
  58. if ( !empty($_FILES['resume']['name'])) {
  59. if(in_array($extension, $allowed_extensions)){
  60. $mail->addAttachment($_FILES['resume']['tmp_name'],
  61. $_FILES['resume']['name']);
  62. }
  63. else{
  64. $exceptionValidate = array(
  65. 'status' => false,
  66. 'error' => 'resume',
  67. 'message' => ' File type not allowed',
  68. );
  69. };
  70. }
  71.  
  72. if ( !empty($_FILES['coverLetter']['name'])) {
  73. if (in_array($extensionFileTwo, $allowed_extensions)) {
  74. $mail->addAttachment($_FILES['coverLetter']['tmp_name'],
  75. $_FILES['coverLetter']['name']);
  76. } else {
  77. $exceptionValidate = array(
  78. 'status' => false,
  79. 'error' => 'coverLetter',
  80. 'message' => ' File type not allowed',
  81. );
  82. };
  83. }
  84.  
  85. $mail->isHTML(true); // Set email format to HTML
  86. $mail->Subject = 'Here is the subject';
  87. $mail->Body = $text;
  88. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  89.  
  90. if (!empty($exceptionValidate)) {
  91. $showresult = $exceptionValidate;
  92. } else {
  93. if (!$mail->send()) {
  94. $showresult = array(
  95. 'status' => false,
  96. 'error' => '',
  97. 'message' => "Email not sent: " . $mail->ErrorInfo,
  98. );
  99.  
  100. } else {
  101. $showresult = array(
  102. 'status' => true,
  103. 'error' => 'SUCCESS',
  104. 'message' => '',
  105. );
  106. }
  107. }
  108.  
  109. header('Content-Type: application/json');
  110. echo json_encode($showresult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement