test_smtp_advanced_no_auth.php 1.5 KB

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