Guest User

Untitled

a guest
Jun 16th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2. require_once('class.phpmailer.php');
  3.  
  4. $errors = array(); // array to hold validation errors
  5. $data = array(); // array to pass back data
  6.  
  7. // validate the variables ======================================================
  8. if (empty($_POST['name']))
  9. $errors['name'] = 'Name is required.';
  10.  
  11. if (empty($_POST['superheroAlias']))
  12. $errors['superheroAlias'] = 'E-mail is required.';
  13.  
  14. if (empty($_POST['content']))
  15. $errors['content'] = 'Message is required.';
  16.  
  17. // return a response ===========================================================
  18.  
  19. // response if there are errors
  20. if ( ! empty($errors)) {
  21.  
  22. // if there are items in our errors array, return those errors
  23. $data['success'] = false;
  24. $data['errors'] = $errors;
  25.  
  26. } else {
  27. $mail = new PHPMailer(); // create a new object
  28. $mail->IsSMTP(); // enable SMTP
  29. $mail->SMTPAuth = true; // authentication enabled
  30. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  31. $mail->Host = "smtp.gmail.com";
  32. $mail->Port = 465; // or 587
  33. $mail->IsHTML(true);
  34. $mail->Username = ""; //Email that you setup
  35. $mail->Password = ""; // Password
  36. $mail->Subject = "Y-Web Contact mail from " . $_POST['name'] . ", e-mail: " .$_POST['superheroAlias']. "";
  37. $mail->Body = $_POST['content'];
  38. $mail->AddAddress(""); //Pass the e-mail that you setup
  39. if(!$mail->Send())
  40. {
  41. echo "Mailer Error: " . $mail->ErrorInfo;
  42. }
  43. else
  44. {
  45. $data['success'] = true;
  46. $data['message'] = 'Thank you for sending e-mail.';
  47. }
  48.  
  49.  
  50. }
  51. echo json_encode($data);
Add Comment
Please, Sign In to add comment