Guest User

Untitled

a guest
Nov 26th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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 '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 = 'email'; // SMTP username
  18. $mail->Password = 'password'; // 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('from email ex: user@gmail.com', 'Smart Distribution System');
  24. $mail->addAddress('who will receive email', 'name of receiver'); // Add a recipient
  25. // $mail->addAddress('ellen@example.com'); // Name is optional
  26. //$mail->addReplyTo('info@example.com', 'Information');
  27. // $mail->addCC('cc@example.com');
  28. // $mail->addBCC('bcc@example.com');
  29.  
  30. // //Attachments
  31. // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  32. // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  33.  
  34. //Content
  35. $mail->isHTML(true); // Set email format to HTML
  36. $mail->Subject = 'subject';
  37. $mail->Body = 'body';
  38. $mail->AltBody = 'altbody';
  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. }
Add Comment
Please, Sign In to add comment