Advertisement
abouttr3

SEND EMAIL

Jan 24th, 2016
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. public static function sendEmail($to, $subject, $message, $json){
  2.         $mail = new PHPMailer;
  3.         $mail->isSMTP();                                      // Set mailer to use SMTP
  4.         $mail->Host = 'localhost';  // Specify main and backup SMTP servers
  5.         //$mail->SMTPAuth = true;                               // Enable SMTP authentication
  6.         //$mail->Username = 'user@example.com';                 // SMTP username
  7.         //$mail->Password = 'secret';                           // SMTP password
  8.         $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  9.         //$mail->Port = 587;                                    // TCP port to connect to
  10.  
  11.         $mail->setFrom('email@example.com', 'Admin');
  12.         $mail->addAddress($to);     // Add a recipient
  13.         //$mail->addAddress('ellen@example.com');               // Name is optional
  14.         $mail->addReplyTo('email@example.com', 'Information');
  15.         //$mail->addCC('cc@example.com');
  16.         //$mail->addBCC('bcc@example.com');
  17.  
  18.         //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
  19.         //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
  20.         $mail->isHTML(true);                                  // Set email format to HTML
  21.  
  22.         $mail->Subject = $subject;
  23.         $mail->Body    = $message;
  24.         //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  25.  
  26.         if(!$mail->send()) {
  27.             $json->statusCode = UNABLE_SENT_EMAIL;
  28.             $json->error= UNABLE_SENT_EMAIL_MESSAGE;
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement