test_smtp_advanced.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <html>
  2. <head>
  3. <title>PHPMailer - SMTP advanced test with 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->SMTPAuth = true; // enable SMTP authentication
  15. $mail->Host = "mail.yourdomain.com"; // sets the SMTP server
  16. $mail->Port = 26; // set the SMTP port for the GMAIL server
  17. $mail->Username = "yourname@yourdomain"; // SMTP account username
  18. $mail->Password = "yourpassword"; // SMTP account password
  19. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  20. $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  21. $mail->SetFrom('name@yourdomain.com', 'First Last');
  22. $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  23. $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  24. $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  25. $mail->MsgHTML(file_get_contents('contents.html'));
  26. $mail->AddAttachment('images/phpmailer.gif'); // attachment
  27. $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  28. $mail->Send();
  29. echo "Message Sent OK</p>\n";
  30. } catch (phpmailerException $e) {
  31. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  32. } catch (Exception $e) {
  33. echo $e->getMessage(); //Boring error messages from anything else!
  34. }
  35. ?>
  36. </body>
  37. </html>