Advertisement
Guest User

phpmailer

a guest
Jan 31st, 2018
2,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2.  
  3. // Import PHPMailer classes into the global namespace
  4. // These must be at the top of your script, not inside a function
  5.  
  6. use PHPMailer\PHPMailer\PHPMailer;
  7. use PHPMailer\PHPMailer\Exception;
  8.  
  9. require 'src/Exception.php';
  10. require 'src/PHPMailer.php';
  11. require 'src/SMTP.php';
  12.  
  13. //Load composer's autoloader
  14. require 'vendor/autoload.php';
  15.  
  16. $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
  17. try {
  18.     //Server settings
  19.     $mail->SMTPDebug = 1;                                 // Enable verbose debug output
  20.     $mail->isSMTP();                                      // Set mailer to use SMTP
  21.     $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
  22.     $mail->SMTPAuth = true;                               // Enable SMTP authentication
  23.     $mail->Username = 'tibiarodepanda@gmail.com';                 // SMTP username
  24.     $mail->Password = 'rodepanda123';                           // SMTP password
  25.     $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
  26.     $mail->Port = 465;                                    // TCP port to connect to
  27.  
  28.     //Recipients
  29.     $mail->setFrom('tibiarodepanda@gmail.com', 'Mailer');
  30.     $mail->addAddress('davidboy_112@live.nl',);     // Add a recipient
  31.  
  32.  
  33.     //Content
  34.     $mail->isHTML(true);                                  // Set email format to HTML
  35.     $mail->Subject = 'Here is the subject';
  36.     $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  37.     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  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