Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. require_once 'phpmailer/PHPMailerAutoload.php';
  5.  
  6. if (isset($_POST['inputName']) && isset($_POST['inputEmail'])&& isset($_POST['inputMessage'])) {
  7.  
  8. //check if any of the inputs are empty
  9. if (empty($_POST['inputName']) || empty($_POST['inputEmail']) ||empty($_POST['inputMessage'])) {
  10. $data = array('success' => false, 'message' => 'Please fill out the form completely.');
  11. echo json_encode($data);
  12. exit;
  13. }
  14.  
  15.  
  16. //
  17. // Please make sure that you verify all the user input values before execute the below code
  18. //
  19.  
  20. //create an instance of PHPMailer
  21. $mail = new PHPMailer();
  22. $mail->isSMTP();
  23.  
  24. $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  25. $mail->SMTPAuth = true; // Enable SMTP authentication
  26. $mail->Username = 'user@example.com'; // SMTP username
  27. $mail->Password = 'secret'; // SMTP password
  28. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  29. $mail->Port = 587; // TCP port to connect to
  30.  
  31. $mail->From = $_POST['inputEmail']; // this need to be your email account: noreply@mysite.com for example
  32. $mail->FromName = $_POST['inputName']; // this need to be your site title: My Site | Description
  33. // $mail->AddAddress('hola@iberomedia.com'); // recipient
  34. $mail->AddAddress( $_POST['inputEmail'] )
  35. $mail->Subject = 'Enquiry from Dexter';
  36. $mail->Body = "Name: " . $_POST['inputName'] . "\r\n\r\nMessage: " . stripslashes($_POST['inputMessage']);
  37.  
  38. if (isset($_POST['ref'])) {
  39. $mail->Body .= "\r\n\r\nRef: " . $_POST['ref'];
  40. }
  41.  
  42. if(!$mail->send()) {
  43. $data = array('success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo);
  44. echo json_encode($data);
  45. exit;
  46. }
  47.  
  48. $data = array('success' => true, 'message' => 'Thanks! We have received your message.');
  49. echo json_encode($data);
  50.  
  51. } else {
  52.  
  53. $data = array('success' => false, 'message' => 'Please fill out the form completely.');
  54. echo json_encode($data);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement