Guest User

Untitled

a guest
Oct 11th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. use PHPMailer\PHPMailer\Exception;
  5.  
  6. require 'phpmailer/src/Exception.php';
  7. require 'phpmailer/src/PHPMailer.php';
  8. require 'phpmailer/src/SMTP.php';
  9.  
  10. $mail = new PHPMailer(true); // Passing `true` enables exceptions to be thrown when something goes wrong
  11.  
  12. try {
  13.  
  14. // SERVER SETTINGS
  15. // $mail->SMTPDebug = 2; // Enable verbose debug output
  16. $mail->isSMTP(); // Set mailer to use SMTP
  17. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  18. $mail->SMTPAuth = true; // Enable SMTP authentication
  19. $mail->Username = 'gustavoalbuquerquebr@gmail.com'; // SMTP username
  20. $mail->Password = 'password'; // SMTP password
  21. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  22. $mail->Port = 587; // TCP port to connect to
  23.  
  24. // PEOPLE
  25. $mail->setFrom('gustavoalbuquerquebr@gmail.com', 'Mailer');
  26. $mail->addAddress('gustavoalbuquerquebr@outlook.com', 'Recipient');
  27. $mail->addReplyTo('gustavoalbuquerquebr@gmail.com', 'ReplyTo');
  28. // $mail->addCC('cc@example.com');
  29. // $mail->addBCC('bcc@example.com');
  30.  
  31. // ATTACHMENTS
  32. $mail->addAttachment('phpmailer.zip', 'mailer.zip'); // Second paremeter is optional
  33.  
  34. // CONTENT
  35. $mail->isHTML(true); // Set email format to HTML
  36. $mail->Subject = 'Here is the subject';
  37. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  38. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  39.  
  40. $mail->send();
  41.  
  42. echo 'Message has been sent';
  43.  
  44. } catch (Exception $e) {
  45. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  46. }
Add Comment
Please, Sign In to add comment