Want more features on Pastebin? Sign Up, it's FREE!
Guest

PhpMailer

By: a guest on Nov 21st, 2012  |  syntax: PHP  |  size: 1.92 KB  |  views: 138  |  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. <?php
  2. //requiring PHPMailer class
  3. require_once('/var/www/somesite.com/public_html/folder1/classes/phpmailer/class.phpmailer.php');
  4.  
  5.  
  6. $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  7.  
  8.  
  9.  
  10. $con = mysql_connect("localhost","root","pass123");
  11. if (!$con)
  12. {
  13.         die('could not connect: '.mysql_error());
  14. } else {
  15.         echo "connected!";
  16.         echo "<br />";
  17. }
  18.  
  19. mysql_select_db("mydb", $con);
  20. mysql_set_charset('utf8',$con);
  21. $result = mysql_query("SELECT * FROM messages");
  22.  
  23. while($row = mysql_fetch_array($result))
  24. {      
  25.         if (!$row['issent']) {
  26.         $message_id = $row['id'];
  27.         $user_id = $row['user_id'];
  28.         $contact_id = $row['contact_id'];
  29.         $subject = $row['subject'];
  30.         $message = $row['message'];
  31.         $user_email = getemail('users', $user_id, 1);
  32.         $contact_email = getemail('contacts', $contact_id, 6);
  33.         echo "Your message"."<br />"."From: ".$user_email."<br />"."To: ".$contact_email."<br />"."Subject: ".$subject."<br />"."Message: ".$message."<br />";
  34.  
  35.  
  36. $mail->IsMail(); // telling the class to use php mail();
  37. $mail->SetFrom('my@email.com', 'The Guy');
  38. $mail->AddReplyTo('my@email.com', 'The Guy');
  39. $mail->Subject    = $subject;
  40. $mail->MsgHTML($message);
  41. $address = $contact_email;
  42. $mail->AddAddress($address, "");
  43.  
  44.  
  45. $mail->CharSet = 'utf-8';
  46. if(!$mail->Send()) {
  47.   echo "Mailer Error: " . $mail->ErrorInfo;
  48.  
  49. } else {
  50.  
  51.   echo "Message sent!";
  52.   $sql = 'UPDATE messages SET issent=1 WHERE id='.$message_id;
  53.   $result2 = mysql_query($sql);
  54.         }
  55. }      
  56. }
  57.  
  58. function getemail($table, $id, $column){
  59. //getting user or contact email by the id, table and column number
  60.         $sql = 'SELECT * FROM '.$table.' WHERE id='.$id;
  61.         $result_email= mysql_query($sql);
  62.         if (!$result_email) {
  63.                 echo 'Could not run query: ' . mysql_error();
  64.                 exit;
  65.         }
  66.         $emailrow = mysql_fetch_row($result_email);
  67.         echo "<br />";
  68.         return $emailrow[$column]; //email
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. mysql_close($con);
  78.  
  79. ?>
clone this paste RAW Paste Data