Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. /**
  3. * This example shows making an SMTP connection with authentication.
  4. */
  5.  
  6. //SMTP needs accurate times, and the PHP time zone MUST be set
  7. //This should be done in your php.ini, but this is how to do it if you don't
  8. have access to that
  9. date_default_timezone_set('Etc/UTC');
  10.  
  11. require '../PHPMailerAutoload.php';
  12.  
  13. //Create a new PHPMailer instance
  14. $mail = new PHPMailer;
  15. //Tell PHPMailer to use SMTP
  16. $mail->isSMTP();
  17. //Enable SMTP debugging
  18. // 0 = off (for production use)
  19. // 1 = client messages
  20. // 2 = client and server messages
  21. $mail->SMTPDebug = 2;
  22. //Ask for HTML-friendly debug output
  23. $mail->Debugoutput = 'html';
  24. //Set the hostname of the mail server
  25. $mail->Host = "smtp.gmail.com";
  26.  
  27. $mail->SMTPSecure = 'tls'; // Enable TLS
  28. encryption, `ssl` also accepted
  29. //Set the SMTP port number - likely to be 25, 465 or 587
  30. $mail->Port = 587;
  31. //Whether to use SMTP authentication
  32. $mail->SMTPAuth = true;
  33. //Username to use for SMTP authentication
  34. $mail->Username = "xxxx@gmail.com";
  35. //Password to use for SMTP authentication
  36. $mail->Password = "xxx";
  37. //Set who the message is to be sent from
  38. $mail->setFrom('xxx@gmail.com', 'First Last');
  39. //Set an alternative reply-to address
  40. $mail->addReplyTo('replyto@example.com', 'First Last');
  41. //Set who the message is to be sent to
  42. $mail->addAddress('xxxx@gmail.com', 'John Doe');
  43. //Set the subject line
  44. $mail->Subject = 'PHPMailer SMTP test';
  45. //Read an HTML message body from an external file, convert referenced images
  46. to embedded,
  47. //convert HTML into a basic plain-text alternative body
  48. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  49. //Replace the plain text body with one created manually
  50. $mail->AltBody = 'This is a plain-text message body';
  51. //Attach an image file
  52. //$mail->addAttachment('images/phpmailer_mini.png');
  53.  
  54. //send the message, check for errors
  55. if (!$mail->send()) {
  56. echo "Mailer Error: " . $mail->ErrorInfo;
  57. } else {
  58. echo "Message sent!";
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement