Guest User

Untitled

a guest
Nov 12th, 2017
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. // Import PHPMailer classes into the global namespace
  3. // These must be at the top of your script, not inside a function
  4. use PHPMailerPHPMailerPHPMailer;
  5. use PHPMailerPHPMailerException;
  6.  
  7. //Load composer's autoloader
  8. require 'PHPMailer/vendor/autoload.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 = 'barussivendas@gmail.com'; // SMTP username
  18. $mail->Password = 'MinhSenha'; // SMTP password
  19. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  20. $mail->Port = 587; // TCP port to connect to
  21.  
  22. //Recipients
  23. $mail->setFrom('lhbs1515@gmail.com', 'Mailer');
  24. $mail->addAddress('lhbs1515@gmail.com', 'Joe User'); // Add a recipient
  25.  
  26.  
  27. //Content
  28. $mail->isHTML(true); // Set email format to HTML
  29. $mail->Subject = 'Here is the subject';
  30. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  31. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  32.  
  33. $mail->send();
  34. echo 'Message has been sent';
  35. } catch (Exception $e) {
  36. echo 'Message could not be sent.';
  37. echo 'Mailer Error: ' . $mail->ErrorInfo;
  38. }
Add Comment
Please, Sign In to add comment