Guest User

Untitled

a guest
Mar 5th, 2018
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. $mail = new PHPMailer(true);
  2.  
  3. <?php
  4. // Import PHPMailer classes into the global namespace
  5. // These must be at the top of your script, not inside a function
  6. use vendorPHPMailerPHPMailerPHPMailer;
  7. use vendorPHPMailerPHPMailerException;
  8.  
  9.  
  10. //Load composer's autoloader
  11. require 'vendor/autoload.php';
  12.  
  13. try{
  14. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  15. }catch(Exception $e){
  16. echo($e);
  17. }
  18.  
  19. try {
  20.  
  21.  
  22. //Server settings
  23. $mail->SMTPDebug = 4; // Enable verbose debug output
  24. $mail->isSMTP(); // Set mailer to use SMTP
  25. $mail->Host = 'aspmx.l.google.com'; // Specify main and backup SMTP servers
  26. $mail->SMTPAuth = true; // Enable SMTP authentication
  27. $mail->Username = 'test@gmail.com'; // SMTP username
  28. $mail->Password = 'testpassword'; // SMTP password
  29. //$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  30. $mail->Port = 25; // TCP port to connect to
  31.  
  32. //Recipients
  33. $mail->setFrom('test@gmail.com', "Test");
  34. $mail->addAddress('test@gmail.com', 'TEst'); // Add a recipient
  35.  
  36.  
  37. //Content
  38. $mail->isHTML(true); // Set email format to HTML
  39. $mail->Subject = 'Here is the subject';
  40. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  41. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  42.  
  43. $mail->send();
  44. echo 'Message has been sent';
  45. } catch (Exception $e) {
  46.  
  47. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  48.  
  49. }
  50.  
  51. ?>
Add Comment
Please, Sign In to add comment