test_pop_before_smtp_advanced.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <head>
  3. <title>POP before SMTP Test</title>
  4. </head>
  5. <body>
  6. <?php
  7. require_once('../class.phpmailer.php');
  8. require_once('../class.pop3.php'); // required for POP before SMTP
  9. $pop = new POP3();
  10. $pop->Authorise('pop3.yourdomain.com', 110, 30, 'username', 'password', 1);
  11. $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  12. $mail->IsSMTP();
  13. try {
  14. $mail->SMTPDebug = 2;
  15. $mail->Host = 'pop3.yourdomain.com';
  16. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  17. $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  18. $mail->SetFrom('name@yourdomain.com', 'First Last');
  19. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  20. $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  21. $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  22. $mail->MsgHTML(file_get_contents('contents.html'));
  23. $mail->AddAttachment('images/phpmailer.gif'); // attachment
  24. $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  25. $mail->Send();
  26. echo "Message Sent OK</p>\n";
  27. } catch (phpmailerException $e) {
  28. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  29. } catch (Exception $e) {
  30. echo $e->getMessage(); //Boring error messages from anything else!
  31. }
  32. ?>
  33. </body>
  34. </html>