Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. //Import the PHPMailer class into the global namespace
  3. use PHPMailer\PHPMailer\PHPMailer;
  4.  
  5. //Load Composer's autoloader
  6. require 'vendor/autoload.php';
  7.  
  8. $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
  9. try {
  10.     //Server settings
  11.     $mail->SMTPDebug = 2;                                 // Enable verbose debug output
  12.     $mail->isSMTP();                                      // Set mailer to use SMTP
  13.     $mail->Host = 'my-ip';  // Specify main and backup SMTP servers
  14.     $mail->SMTPAuth = true;                               // Enable SMTP authentication
  15.     $mail->Username = 'dev@test.work';                 // SMTP username
  16.     $mail->Password = '123456';                           // SMTP password
  17.     // $mail->Port = 27;                                    // TCP port to connect to
  18.     $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  19.     $mail->Port = 587;                                    // TCP port to connect to
  20.  
  21.     //Recipients
  22.     $mail->setFrom('dev@test.work', 'Mailer');
  23.     $mail->addAddress('test@test.work');     // Add a recipient
  24.     $mail->addAddress('test2@test.work');               // Name is optional
  25.  
  26.     //Content
  27.     $mail->isHTML(true);                                  // Set email format to HTML
  28.     $mail->Subject = 'Here is the subject';
  29.     $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  30.     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  31.  
  32.     $mail->SMTPOptions = array(
  33.         'ssl' => array(
  34.             'verify_peer' => false,
  35.             'verify_peer_name' => false,
  36.             'allow_self_signed' => true
  37.         )
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement