Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: PHP  |  size: 2.19 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3. <title>PHPMailer - MySQL Database - SMTP basic test with authentication</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8.  
  9. //error_reporting(E_ALL);
  10. error_reporting(E_STRICT);
  11.  
  12. date_default_timezone_set('America/Toronto');
  13.  
  14. require_once('class.phpmailer.php');
  15. //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  16.  
  17. $mail                = new PHPMailer();
  18.  
  19. $body                = file_get_contents('contents.html');
  20. $body                = eregi_replace("[\]",'',$body);
  21.  
  22. $mail->IsSMTP(); // telling the class to use SMTP
  23. $mail->Host          = "smtp1.site.com;smtp2.site.com";
  24. $mail->SMTPAuth      = true;                  // enable SMTP authentication
  25. $mail->SMTPKeepAlive = true;                  // SMTP connection will not close after each email sent
  26. $mail->Host          = "mail.yourdomain.com"; // sets the SMTP server
  27. $mail->Port          = 26;                    // set the SMTP port for the GMAIL server
  28. $mail->Username      = "yourname@yourdomain"; // SMTP account username
  29. $mail->Password      = "yourpassword";        // SMTP account password
  30. $mail->SetFrom('list@mydomain.com', 'List manager');
  31. $mail->AddReplyTo('list@mydomain.com', 'List manager');
  32.  
  33. $mail->Subject       = "PHPMailer Test Subject via smtp, basic with authentication";
  34.  
  35. @MYSQL_CONNECT("localhost","root","password");
  36. @mysql_select_db("my_company");
  37. $query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
  38. $result = @MYSQL_QUERY($query);
  39.  
  40. while ($row = mysql_fetch_array ($result)) {
  41.   $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  42.   $mail->MsgHTML($body);
  43.   $mail->AddAddress($row["email"], $row["full_name"]);
  44.   $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
  45.  
  46.   if(!$mail->Send()) {
  47.     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
  48.   } else {
  49.     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br />';
  50.   }
  51.   // Clear all addresses and attachments for next loop
  52.   $mail->ClearAddresses();
  53.   $mail->ClearAttachments();
  54. }
  55. ?>
  56.  
  57. </body>
  58. </html>