Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2018
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 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. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  11. try {
  12. $mail->SMTPOptions = array(
  13. 'ssl' => array(
  14. 'verify_peer' => false,
  15. 'verify_peer_name' => false,
  16. 'allow_self_signed' => true
  17. )
  18. );
  19. //Server settings
  20. $mail->SMTPDebug = 2; // Enable verbose debug output
  21. $mail->isSMTP(); // Set mailer to use SMTP
  22. $mail->Host = gethostbyname("smtp.gmail.com"); // Specify main and backup SMTP servers
  23. $mail->SMTPAuth = true; // Enable SMTP authentication
  24. $mail->Username = ''; // SMTP username
  25. $mail->Password = ''; // SMTP password
  26. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  27. $mail->Port = 587; // TCP port to connect to
  28.  
  29. //Recipients
  30. $mail->setFrom('hunterkelwa@gmail.com');
  31. $mail->addAddress('moaaztaha7@gmail.com'); // Add a recipient
  32.  
  33.  
  34. //Content
  35. $mail->isHTML(true); // Set email format to HTML
  36. $mail->Subject = 'Here is the subject';
  37. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  38. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  39.  
  40. $mail->send();
  41. echo 'Message has been sent';
  42. } catch (Exception $e) {
  43. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement