pop_before_smtp.phps 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>PHPMailer - POP-before-SMTP test</title>
  6. </head>
  7. <body>
  8. <?php
  9. require '../PHPMailerAutoload.php';
  10. //Authenticate via POP3.
  11. //After this you should be allowed to submit messages over SMTP for a while.
  12. //Only applies if your host supports POP-before-SMTP.
  13. $pop = POP3::popBeforeSmtp('pop3.example.com', 110, 30, 'username', 'password', 1);
  14. //Create a new PHPMailer instance
  15. //Passing true to the constructor enables the use of exceptions for error handling
  16. $mail = new PHPMailer(true);
  17. try {
  18. $mail->isSMTP();
  19. //Enable SMTP debugging
  20. // 0 = off (for production use)
  21. // 1 = client messages
  22. // 2 = client and server messages
  23. $mail->SMTPDebug = 2;
  24. //Ask for HTML-friendly debug output
  25. $mail->Debugoutput = 'html';
  26. //Set the hostname of the mail server
  27. $mail->Host = "mail.example.com";
  28. //Set the SMTP port number - likely to be 25, 465 or 587
  29. $mail->Port = 25;
  30. //Whether to use SMTP authentication
  31. $mail->SMTPAuth = false;
  32. //Set who the message is to be sent from
  33. $mail->setFrom('from@example.com', 'First Last');
  34. //Set an alternative reply-to address
  35. $mail->addReplyTo('replyto@example.com', 'First Last');
  36. //Set who the message is to be sent to
  37. $mail->addAddress('whoto@example.com', 'John Doe');
  38. //Set the subject line
  39. $mail->Subject = 'PHPMailer POP-before-SMTP test';
  40. //Read an HTML message body from an external file, convert referenced images to embedded,
  41. //and convert the HTML into a basic plain-text alternative body
  42. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  43. //Replace the plain text body with one created manually
  44. $mail->AltBody = 'This is a plain-text message body';
  45. //Attach an image file
  46. $mail->addAttachment('images/phpmailer_mini.png');
  47. //send the message
  48. //Note that we don't need check the response from this because it will throw an exception if it has trouble
  49. $mail->send();
  50. echo "Message sent!";
  51. } catch (phpmailerException $e) {
  52. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  53. } catch (Exception $e) {
  54. echo $e->getMessage(); //Boring error messages from anything else!
  55. }
  56. ?>
  57. </body>
  58. </html>