Advertisement
Guest User

Untitled

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