Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
378
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. // Import PHPMailer classes into the global namespace
  3. // These must be at the top of your script, not inside a function
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPMailer\PHPMailer\Exception;
  6.  
  7. //Load composer's autoloader
  8. require 'vendor/autoload.php';
  9.  
  10.  
  11. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  12. try {
  13. //Server settings
  14. $mail->SMTPDebug = 2; // Enable verbose debug output
  15. $mail->isSMTP(); // Set mailer to use SMTP
  16. $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  17. $mail->SMTPAuth = true; // Enable SMTP authentication
  18. $mail->Username = 'user@example.com'; // SMTP username
  19. $mail->Password = 'secret'; // SMTP password
  20. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  21. $mail->Port = 587; // TCP port to connect to
  22.  
  23. //Recipients
  24. $mail->setFrom('studentuitm1108@gmail', 'Mailer');
  25. $mail->addAddress('darkvisitor99@gmail.com', 'Test'); // Add a recipient
  26. $mail->addReplyTo('noreply@gmail.com', 'Information');
  27.  
  28.  
  29. //Content
  30. $mail->isHTML(true); // Set email format to HTML
  31. $mail->Subject = 'Hello';
  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. $mail->send();
  36. echo 'Message has been sent';
  37. } catch (Exception $e) {
  38. echo 'Message could not be sent.';
  39. echo 'Mailer Error: ' . $mail->ErrorInfo;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement