Advertisement
RicardasSim

PHPMailer tls 587

Jan 28th, 2019
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. //PHPMailer page: https://github.com/PHPMailer/PHPMailer
  3.  
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPMailer\PHPMailer\Exception;
  6.  
  7. require 'PHPMailer/src/Exception.php';
  8. require 'PHPMailer/src/PHPMailer.php';
  9. require 'PHPMailer/src/SMTP.php';
  10.  
  11. $mail = new PHPMailer(true); //Passing 'true' enables exceptions
  12. try {
  13.  
  14.     $mail->CharSet = 'UTF-8';
  15.     $mail->SMTPDebug = 2;   //0 1 2 3 4              
  16.     $mail->isSMTP();
  17.     $mail->Host = 'mail.example.com';  
  18.     $mail->SMTPAuth = true;
  19.     $mail->Username = 'user@example.com';
  20.     $mail->Password = 'password';          
  21.     $mail->SMTPSecure = 'tls';
  22.     $mail->Port = 587;
  23.     $mail->SMTPOptions = array(
  24.         'ssl' => array(
  25.             'verify_peer' => false,
  26.             'verify_peer_name' => false,
  27.             'allow_self_signed' => true
  28.         )
  29.     );
  30.     $mail->setFrom('user@example.com', 'Mailer');
  31.     $mail->addAddress('user2@example.com', 'Example User');
  32.     $mail->addReplyTo('info@example.com', 'Information');
  33.  
  34.     $mail->isHTML(true);
  35.     $mail->Subject = 'Testas iš PHPMailer.';
  36.     $mail->Body    = 'Testas iš PHPMailer. Tikriname ar veikia paštas.';
  37.     $mail->AltBody = 'Testas is PHPMailer. Tikriname ar veikia pastas.';
  38.  
  39.     $mail->send();
  40.     echo 'Message has been sent';
  41. } catch (Exception $e) {
  42.     echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement