test_smtp_basic.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <html>
  2. <head>
  3. <title>PHPMailer - SMTP basic test with authentication</title>
  4. </head>
  5. <body>
  6. <?php
  7. //error_reporting(E_ALL);
  8. error_reporting(E_STRICT);
  9. date_default_timezone_set('America/Toronto');
  10. require_once('../class.phpmailer.php');
  11. //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  12. $mail = new PHPMailer();
  13. $body = file_get_contents('contents.html');
  14. $body = eregi_replace("[\]",'',$body);
  15. $mail->IsSMTP(); // telling the class to use SMTP
  16. $mail->Host = "mail.yourdomain.com"; // SMTP server
  17. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  18. // 1 = errors and messages
  19. // 2 = messages only
  20. $mail->SMTPAuth = true; // enable SMTP authentication
  21. $mail->Host = "mail.yourdomain.com"; // sets the SMTP server
  22. $mail->Port = 26; // set the SMTP port for the GMAIL server
  23. $mail->Username = "yourname@yourdomain"; // SMTP account username
  24. $mail->Password = "yourpassword"; // SMTP account password
  25. $mail->SetFrom('name@yourdomain.com', 'First Last');
  26. $mail->AddReplyTo("name@yourdomain.com","First Last");
  27. $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
  28. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  29. $mail->MsgHTML($body);
  30. $address = "whoto@otherdomain.com";
  31. $mail->AddAddress($address, "John Doe");
  32. $mail->AddAttachment("images/phpmailer.gif"); // attachment
  33. $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
  34. if(!$mail->Send()) {
  35. echo "Mailer Error: " . $mail->ErrorInfo;
  36. } else {
  37. echo "Message sent!";
  38. }
  39. ?>
  40. </body>
  41. </html>