Advertisement
Guest User

Untitled

a guest
Dec 18th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2. //require 'PHPMailer-master/PHPMailerAutoload.php';
  3. //header('Content-Type: application/json');
  4.  
  5. $errors = array();
  6.  
  7. $title = (isset($_POST['title']) && ($_POST['title'] != '0')) ? $_POST['title'] : null;
  8. $firstName = (isset($_POST['firstName']) && !(empty($_POST["firstName"]))) ? $_POST['firstName'] : null;
  9. $lastName = (isset($_POST['lastName']) && !(empty($_POST["lastName"]))) ? $_POST['lastName'] : null;
  10. $emailAddress = (isset($_POST['emailAddress']) && !(empty($_POST["emailAddress"]))) ? $_POST['emailAddress'] : null;
  11. $website = isset($_POST['website']) ? $_POST['website'] : '';
  12. $message = (isset($_POST['message']) && !(empty($_POST["message"]))) ? $_POST['message'] : null;
  13.  
  14. if ($title === null) {
  15. $errors[] = 'You must select a title';
  16. }
  17.  
  18. if ($firstName === null) {
  19. $errors[] = 'You must enter a first name';
  20. }
  21.  
  22. if ($lastName === null) {
  23. $errors[] = 'You must enter a last name';
  24. }
  25.  
  26. if ($emailAddress === null || filter_var($emailAddress, FILTER_VALIDATE_EMAIL) === false) {
  27. $errors[] = 'You must enter a valid email address';
  28. }
  29.  
  30. if ($website !== '') {
  31. if(strpos($website, '://') === false) {
  32. $website = 'http://' . $website;
  33. }
  34.  
  35. if (filter_var($website, FILTER_VALIDATE_URL, array('flags' => null)) === false) {
  36. $errors[] = 'You must enter a valid website address';
  37. }
  38. }
  39.  
  40. if ($message === null) {
  41. $errors[] = 'You must enter a message';
  42. }
  43.  
  44. if (empty($errors)) {
  45. require __DIR__ . '/PHPMailer-master/PHPMailerAutoload.php';
  46.  
  47. //SMTP needs accurate times, and the PHP time zone MUST be set
  48. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  49. date_default_timezone_set('Etc/UTC');
  50.  
  51. /* $mail = new PHPMailer;
  52. $mail->isSMTP();
  53. $mail->Host = 'smtp.gmail.com';
  54. $mail->Port = 587;
  55. $mail->SMTPSecure = 'tls';
  56. $mail->SMTPAuth = true;
  57. $mail->Username = "bassabasso@gmail.com";
  58. $mail->Password = "xxxxxxxxxxx";
  59.  
  60. $mail->setFrom($emailAddress, $firstName . ' ' . $lastName);
  61. $mail->addAddress('bassabasso@gmail.com', 'Bassa Basso');
  62. $mail->Subject = 'New request';
  63. $mail->Body = $message . "\r\n\r\nWebsite: " . $website; */
  64.  
  65. $mail = new PHPMailer;
  66. $mail->Timeout = 30; // set the timeout (seconds)
  67. $mail->isSMTP();
  68. $mail->SMTPAuth = true; // enable SMTP authentication
  69. $mail->SMTPSecure = "tls"; // sets the prefix to the servier
  70. $mail->Host = "smtp.live.com"; // sets hotmil as the SMTP server
  71. $mail->Port = 587; // set the SMTP port for the hotmail server
  72. $mail->Username = "jasonattin@hotmail.co.uk"; // hotmail username
  73. $mail->Password = "xxxxxxx"; // hotmail password
  74. $mail->setFrom($emailAddress, $firstName . ' ' . $lastName);
  75. $mail->addAddress('jasonattin@hotmail.co.uk', 'Bassa Basso');
  76. $mail->Subject = 'New request';
  77. $mail->Body = $message . "\r\n\r\nWebsite: " . $website;
  78.  
  79.  
  80. if ($mail->send()) {
  81. echo json_encode('Form submitted successfully!');
  82. exit();
  83. }
  84.  
  85. // You may want to log this somewhere
  86. // $mail->ErrorInfo;
  87.  
  88. $errors[] = 'Could not send email, please try again later';
  89. }
  90.  
  91. http_response_code(400);
  92. echo json_encode($errors);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement