Advertisement
Guest User

Untitled

a guest
Aug 15th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2. /**
  3. * This example shows making an SMTP connection with authentication.
  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 = "mail.example.com";
  22. //Set the SMTP port number - likely to be 25, 465 or 587
  23. $mail->Port = 25;
  24. //Whether to use SMTP authentication
  25. $mail->SMTPAuth = true;
  26. //Username to use for SMTP authentication
  27. $mail->Username = "yourname@example.com";
  28. //Password to use for SMTP authentication
  29. $mail->Password = "yourpassword";
  30. //Set who the message is to be sent from
  31. $mail->setFrom('from@example.com', 'First Last');
  32. //Set an alternative reply-to address
  33. $mail->addReplyTo('replyto@example.com', 'First Last');
  34. //Set who the message is to be sent to
  35. $mail->addAddress('whoto@example.com', 'John Doe');
  36. //Set the subject line
  37. $mail->Subject = 'PHPMailer SMTP test';
  38. //Read an HTML message body from an external file, convert referenced images to embedded,
  39. //convert HTML into a basic plain-text alternative body
  40. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  41. //Replace the plain text body with one created manually
  42. $mail->AltBody = 'This is a plain-text message body';
  43. //Attach an image file
  44. $mail->addAttachment('images/phpmailer_mini.png');
  45. //send the message, check for errors
  46. if (!$mail->send()) {
  47. echo "Mailer Error: " . $mail->ErrorInfo;
  48. } else {
  49. echo "Message sent!";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement