Guest User

Untitled

a guest
Jul 9th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3. require_once('class.db.php');
  4. $db = new db();
  5. $db->__connect();
  6.  
  7.  
  8.  
  9. if((!$_GET['pub_id'])||(!$_GET['product_id'])||(!$_GET['mail_id'])){
  10. echo "Need pub id,product id and mail id. Quitting.";
  11. exit;
  12. }
  13.  
  14.  
  15. //get the product
  16. $db->changeDb('DTMS_Tracking'); // The db can be changed here.
  17.  
  18. $product_id = $_GET['product_id'];
  19. $sql = "select * from master_product_table where product_id = $product_id";
  20. $result = $db->fetchQuery($sql);
  21. if(!$result)
  22. {
  23. echo "Product id invalid. Quitting.";
  24. exit;
  25. }
  26. foreach($result as $key => $val)
  27. {
  28. $product = $val;
  29. }
  30.  
  31. //get the publisher
  32. $db->changeDb('emailer_queue'); // The db can be changed here.
  33.  
  34. $pub_id = $_GET['pub_id'];
  35. $sql = "select * from publishers where id = $pub_id";
  36. $result = $db->fetchQuery($sql);
  37. if(!$result)
  38. {
  39. echo "Publisher id invalid. Quitting.";
  40. exit;
  41. }
  42. foreach($result as $key => $val)
  43. {
  44. $publisher = $val;
  45. }
  46.  
  47.  
  48. //get the mail template
  49. $db->changeDb('emailer_queue'); // The db can be changed here.
  50.  
  51. $mail_id = $_GET['mail_id'];
  52. $sql = "select * from prebuilt_emails where id = $mail_id";
  53. $result = $db->fetchQuery($sql);
  54. if(!$result)
  55. {
  56. echo "Mail id invalid. Quitting.";
  57. exit;
  58. }
  59. foreach($result as $key => $val)
  60. {
  61. $mail_template = $val;
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. $user_where = "";
  69. $user_id = $_GET['user_id'];
  70. if($user_id)
  71. {
  72. $user_where = " AND user_id in ($user_id) ";
  73. }
  74.  
  75. $sp_database = $product['product_database'];
  76.  
  77.  
  78.  
  79. $query = "SELECT * FROM $sp_database.users where user_id not in(select user_id from DTMS_Tracking.emails_sent) $user_where";
  80.  
  81. $email_subject = $mail_template['email_subject'];
  82. $email_body = $mail_template['email_body'];
  83. $email_from_name = $product['product_label'];
  84. $product_email_label = $product['product_email_label'];
  85. $email_from_address = "no-reply@$product_email_label";
  86.  
  87. $site_db = $sp_database;
  88.  
  89. //next time
  90. //$query = "SELECT * FROM users where user_id not in (select user_id from users_sent)";
  91.  
  92. //for test
  93. //$query = "SELECT * FROM users where ssn = 1000";
  94. //
  95. $res = $db->fetchQuery($query);
  96.  
  97. //$email_from_name = "IDWarden";
  98. //$email_from_address = "no-reply@idwarden.com";
  99. //$email_subject = "Your ID Theft Program Update";
  100. //$email_body = file_get_contents('1.html');
  101.  
  102. $rate[0]['eph'] = 1000;
  103. $eph = $rate[0]['eph'];
  104. $epm = ($eph / 60);
  105.  
  106.  
  107.  
  108. if($_GET['email'])
  109. {
  110. $specific_email_body = str_replace(array('%%firstname%%','%%username%%','%%password%%'),array($firstname,$username,$password), $email_body);
  111.  
  112. $headers = "Mine-Version: 1.0"."\r\nContent-type: text/html; charset=iso-8859-1\r\n".
  113. "To:".$_GET['email']." <".$_GET['email'].">"."\r\n".
  114. "From:".$email_from_name." <".$email_from_address.">"."\r\n".
  115. "X-Mailer: PHP / ".phpversion();
  116.  
  117. if($_GET['f_name']&&$_GET['l_name'])
  118. {
  119. //update DB firstly.
  120. $name = $_GET['f_name'].' '.$_GET['l_name'];
  121. $email = $_GET['email'];
  122. $sql = "insert into $sp_database.users(name,email) values('$name','$email')";
  123. $db->query($sql);
  124. //
  125. }
  126.  
  127.  
  128. $response = mail('', $email_subject, $specific_email_body, $headers);
  129.  
  130. if($response){
  131. $user_id = $val['user_id'];
  132. $query = "insert into emails_sent(site_db,pub_id,product_id,mail_id,user_id) values('$site_db',$pub_id,$product_id,$mail_id,$user_id)";
  133. $db->query($query);
  134. }
  135. echo "finished";
  136. exit;
  137.  
  138. }
  139. exit;
  140.  
  141. $total = 0;
  142. $stime = time();
  143. foreach($res as $key=>$val){
  144.  
  145.  
  146.  
  147. if($total == $epm)
  148. {
  149. $etime = time();
  150. $sleep_time = $stime + 60 - $etime;
  151. if($sleep_time > 0)sleep($sleep_time);
  152. $stime = $stime + 60;
  153. $total = 0;
  154. }
  155.  
  156. $firstname = $val['first_name'];
  157. $username = $val['phone_number'];
  158. $password = $val['zip'];
  159. $specific_email_body = str_replace(array('%%firstname%%','%%username%%','%%password%%'),array($firstname,$username,$password), $email_body);
  160.  
  161. $headers = "Mine-Version: 1.0"."\r\nContent-type: text/html; charset=iso-8859-1\r\n".
  162. "To:".$val['first_name']." <".$val['email_address'].">"."\r\n".
  163. "From:".$email_from_name." <".$email_from_address.">"."\r\n".
  164. "X-Mailer: PHP / ".phpversion();
  165.  
  166. $response = mail('', $email_subject, $specific_email_body, $headers);
  167.  
  168. if($response){
  169. $user_id = $val['user_id'];
  170. $query = "insert into emails_sent(site_db,pub_id,product_id,mail_id,user_id) values('$site_db',$pub_id,$product_id,$mail_id,$user_id)";
  171. $db->query($query);
  172. }
  173.  
  174. $total++;
  175. }
  176.  
  177. echo "finished";
  178. exit;
  179.  
  180. ?>
Add Comment
Please, Sign In to add comment