test_smtp_gmail_basic.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <html>
  2. <head>
  3. <title>PHPMailer - SMTP (Gmail) basic test</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->SMTPSecure = "ssl"; // sets the prefix to the servier
  22. $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
  23. $mail->Port = 465; // set the SMTP port for the GMAIL server
  24. $mail->Username = "yourusername@gmail.com"; // GMAIL username
  25. $mail->Password = "yourpassword"; // GMAIL password
  26. $mail->SetFrom('name@yourdomain.com', 'First Last');
  27. $mail->AddReplyTo("name@yourdomain.com","First Last");
  28. $mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
  29. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  30. $mail->MsgHTML($body);
  31. $address = "whoto@otherdomain.com";
  32. $mail->AddAddress($address, "John Doe");
  33. $mail->AddAttachment("images/phpmailer.gif"); // attachment
  34. $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
  35. if(!$mail->Send()) {
  36. echo "Mailer Error: " . $mail->ErrorInfo;
  37. } else {
  38. echo "Message sent!";
  39. }
  40. ?>
  41. </body>
  42. </html>