Guest User

Untitled

a guest
Jan 30th, 2018
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. use PHPMailerPHPMailerPHPMailer;
  3. use PHPMailerPHPMailerException;
  4.  
  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
  11. try {
  12. //Server settings
  13. $mail->SMTPDebug = 2; // Enable verbose debug output
  14. $mail->isSMTP(); // Set mailer to use SMTP
  15. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  16. $mail->SMTPAuth = true; // Enable SMTP authentication
  17. $mail->Username = 'yourdummyemail@gmail.com'; // SMTP username
  18. $mail->Password = 'password'; // SMTP password
  19. $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
  20. $mail->Port = 465; // TCP port to connect to
  21.  
  22. //Recipients
  23. $mail->setFrom('noreply@gmail.com', 'Mailer');
  24. $mail->addAddress('youremail@gmail.com', 'Joe User'); // Add a recipient
  25. $mail->isHTML(true); // Set email format to HTML
  26. $mail->Subject = 'Here is the subject';
  27. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  28.  
  29. $mail->send();
  30. echo 'Message has been sent';
  31. } catch (Exception $e) {
  32. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  33. }
  34.  
  35. 2018-01-30 15:03:37 SMTP ERROR: Failed to connect to server: (0)
  36. SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  37. Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Add Comment
Please, Sign In to add comment