Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
94
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. if (isset($_POST['submit'])
  3. {
  4. // Import PHPMailer classes into the global namespace
  5. // These must be at the top of your script, not inside a function
  6. use PHPMailerPHPMailerPHPMailer;
  7. use PHPMailerPHPMailerException;
  8.  
  9. //Load Composer's autoloader
  10. require 'vendor/autoload.php';
  11.  
  12. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  13. try {
  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;smtp-relay.gmail.com'; // Specify main and backup SMTP servers
  18. $mail->SMTPAuth = true; // Enable SMTP authentication
  19. $mail->Username = 'xxxxxxxxx'; // SMTP username
  20. $mail->Password = 'xxxxxxxxx'; // SMTP password
  21. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  22. $mail->Port = 587; // TCP port to connect to
  23.  
  24. //Recipients
  25. $mail->setFrom('xxxxxxxxx', 'xxxxxxxxxx');
  26. $mail->addAddress('xxxxxxxxx', 'xxxxxxxxxx'); // Add a recipient
  27. $mail->addReplyTo('info@example.com', 'Information');
  28.  
  29. //Content
  30. $mail->isHTML(true); // Set email format to HTML
  31. $mail->Subject = 'Here is the subject';
  32. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  33. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  34.  
  35. if(!$mail->Send()) {
  36. echo 'Message could not be sent.';
  37. echo 'Mailer Error: ' . $mail->ErrorInfo;
  38. exit;
  39. }
  40. }
  41. echo 'Message has been sent';
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement