Guest User

Mail Sending Error

a guest
Apr 19th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  5.     try {
  6.         $postdata = file_get_contents("php://input");
  7.         $request = json_decode($postdata);
  8.         $serviceName = $request->service;
  9.  
  10.         if ($serviceName == 'test') {
  11.              $name= $request->name;
  12.  
  13.  require "./class.PHPMailer.php";
  14.  
  15. $mail = new PHPMailer();
  16.  
  17. $mail->IsSMTP();                                      // set mailer to use SMTP
  18. $mail->SMTPSecure = "ssl";
  19.  
  20. $mail->port = "487";
  21.  
  22. $mail->Host = 'ssl://smtp.gmail.com';  // specify main and backup server
  23. $mail->SMTPAuth = true;     // turn on SMTP authentication
  24. $mail->Username = "mygmailid";  // SMTP username
  25. $mail->Password = "password"; // SMTP password
  26.  
  27. $mail->From = "mygmailid";
  28. $mail->FromName = "myname";
  29. $mail->AddAddress("reciepient id", "reciepient name");
  30. $mail->AddAddress("reciepient id");                  // name is optional
  31. $mail->AddReplyTo("reciepient id", "Information");
  32.  
  33. $mail->WordWrap = 50;                                 // set word wrap to 50 characters
  34. $mail->IsHTML(true);                                  // set email format to HTML
  35.  
  36. $mail->Subject = "Here is the subject";
  37. $mail->Body    = "This is the HTML message body in bold!";
  38. $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
  39.  
  40.  
  41.         if(!$mail->Send()){
  42.             $er=$mail->ErrorInfo;
  43.             $json = array("error" => "X", "errorMsg" => $er);
  44.          }else{
  45.             $json = array("error" => "X",  "error" => "Message has been sent");
  46.          }
  47.         echo json_encode($json);
  48.         return;
  49.         } //catch exception
  50.            catch (Exception $e) {
  51.                  $json = array("error" => "X", "errorMsg" => "Some error occured", "error" => $e);
  52.                  echo json_encode($json);
  53.                  }
  54. } else {
  55.     echo "Oops you landed on the wrong page!";
  56. }
  57.  
  58. ?>
Add Comment
Please, Sign In to add comment