Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ($_SERVER['REQUEST_METHOD'] == "POST") {
- try {
- $postdata = file_get_contents("php://input");
- $request = json_decode($postdata);
- $serviceName = $request->service;
- if ($serviceName == 'test') {
- $name= $request->name;
- require "./class.PHPMailer.php";
- $mail = new PHPMailer();
- $mail->IsSMTP(); // set mailer to use SMTP
- $mail->SMTPSecure = "ssl";
- $mail->port = "487";
- $mail->Host = 'ssl://smtp.gmail.com'; // specify main and backup server
- $mail->SMTPAuth = true; // turn on SMTP authentication
- $mail->Username = "mygmailid"; // SMTP username
- $mail->Password = "password"; // SMTP password
- $mail->From = "mygmailid";
- $mail->FromName = "myname";
- $mail->AddAddress("reciepient id", "reciepient name");
- $mail->AddAddress("reciepient id"); // name is optional
- $mail->AddReplyTo("reciepient id", "Information");
- $mail->WordWrap = 50; // set word wrap to 50 characters
- $mail->IsHTML(true); // set email format to HTML
- $mail->Subject = "Here is the subject";
- $mail->Body = "This is the HTML message body in bold!";
- $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
- if(!$mail->Send()){
- $er=$mail->ErrorInfo;
- $json = array("error" => "X", "errorMsg" => $er);
- }else{
- $json = array("error" => "X", "error" => "Message has been sent");
- }
- echo json_encode($json);
- return;
- } //catch exception
- catch (Exception $e) {
- $json = array("error" => "X", "errorMsg" => "Some error occured", "error" => $e);
- echo json_encode($json);
- }
- } else {
- echo "Oops you landed on the wrong page!";
- }
- ?>
Add Comment
Please, Sign In to add comment