smtp_no_auth.phps 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>PHPMailer - SMTP without auth test</title>
  6. </head>
  7. <body>
  8. <?php
  9. //SMTP needs accurate times, and the PHP time zone MUST be set
  10. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  11. date_default_timezone_set('Etc/UTC');
  12. require_once '../PHPMailerAutoload.php';
  13. //Create a new PHPMailer instance
  14. $mail = new PHPMailer();
  15. //Tell PHPMailer to use SMTP
  16. $mail->isSMTP();
  17. //Enable SMTP debugging
  18. // 0 = off (for production use)
  19. // 1 = client messages
  20. // 2 = client and server messages
  21. $mail->SMTPDebug = 2;
  22. //Ask for HTML-friendly debug output
  23. $mail->Debugoutput = 'html';
  24. //Set the hostname of the mail server
  25. $mail->Host = "mail.example.com";
  26. //Set the SMTP port number - likely to be 25, 465 or 587
  27. $mail->Port = 25;
  28. //Whether to use SMTP authentication
  29. $mail->SMTPAuth = false;
  30. //Set who the message is to be sent from
  31. $mail->setFrom('from@example.com', 'First Last');
  32. //Set an alternative reply-to address
  33. $mail->addReplyTo('replyto@example.com', 'First Last');
  34. //Set who the message is to be sent to
  35. $mail->addAddress('whoto@example.com', 'John Doe');
  36. //Set the subject line
  37. $mail->Subject = 'PHPMailer SMTP without auth test';
  38. //Read an HTML message body from an external file, convert referenced images to embedded,
  39. //convert HTML into a basic plain-text alternative body
  40. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  41. //Replace the plain text body with one created manually
  42. $mail->AltBody = 'This is a plain-text message body';
  43. //Attach an image file
  44. $mail->addAttachment('images/phpmailer_mini.gif');
  45. //send the message, check for errors
  46. if (!$mail->send()) {
  47. echo "Mailer Error: " . $mail->ErrorInfo;
  48. } else {
  49. echo "Message sent!";
  50. }
  51. ?>
  52. </body>
  53. </html>