Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. 28
  3. 29
  4. 30
  5. 31
  6. 32
  7. 33
  8. 34
  9. 35
  10. 36
  11. 37
  12. 38
  13. 39
  14. 40
  15. <?php
  16.  
  17. use PHPMailer\PHPMailer\PHPMailer;
  18. use PHPMailer\PHPMailer\Exception;
  19. require 'vendor/autoload.php';
  20.  
  21. $mail = new PHPMailer(true);
  22. try {
  23. //Server settings
  24. $mail->SMTPDebug = 2;
  25. $mail->isSMTP();
  26. $mail->Host = 'smtp.gmail.com';
  27. $mail->SMTPAuth = true;
  28. $mail->Username = 'username@gmail.com';
  29. $mail->Password = '_password_';
  30. $mail->SMTPSecure = 'tls';
  31. $mail->Port = 587;
  32.  
  33.  
  34. $mail->setFrom('sender@example.com', 'Admin');
  35. $mail->addAddress('recipient1@example.net', 'Recipient1');
  36. $mail->addAddress('recipient2@example.com');
  37. $mail->addReplyTo('noreply@example.com', 'noreply');
  38. $mail->addCC('cc@example.com');
  39. $mail->addBCC('bcc@example.com');
  40.  
  41. //Attachments
  42. $mail->addAttachment('/backup/myfile.tar.gz');
  43.  
  44. //Content
  45. $mail->isHTML(true);
  46. $mail->Subject = 'Test Mail Subject!';
  47. $mail->Body = 'This is SMTP Email Test';
  48.  
  49. $mail->send();
  50. echo 'Message has been sent';
  51. } catch (Exception $e) {
  52. echo 'Message could not be sent.';
  53. echo 'Mailer Error: ' . $mail->ErrorInfo;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement