Advertisement
Guest User

Sleep() with mail()

a guest
Apr 3rd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.22 KB | None | 0 0
  1. <?
  2. require_once 'common.php';
  3. //require_once '../lib/editor.php';
  4. require '../lib/template.php';
  5. require_once("../lib/translator.php");
  6.  
  7. set_time_limit(150);
  8.  
  9. $translator = new Translator(1);
  10.  
  11. $sent =(int)$sent;
  12. $id = (int)$id;
  13. $email_template = (int) $email_template;
  14. $email_from = SQLdecode($email_from);
  15. $email_toname = SQLdecode($email_toname);
  16. if(($email_from == "") or (!ereg("^.+@.+\\..+$", $email_from)))
  17.     $email_from = "webmaster@".$SERVER_NAME;
  18.  
  19. foreach($HTTP_POST_VARS as $sForm => $value) {
  20.         //$postedValue = htmlentities( stripslashes( $HTTP_POST_VARS[$sForm] ) ) ;
  21.         //$postedValue = htmlspecialchars( stripslashes( $HTTP_POST_VARS[$sForm] ) ) ;
  22.             $postedValue = stripslashes( $HTTP_POST_VARS[$sForm] ) ;
  23.             if($sForm=="EditorDefault") $content=$postedValue;
  24.             }
  25.         $contentReal=SQLdecode($content);  
  26.         $content=SQLdecode($content);
  27.            
  28. //$content = $EditorContent1;
  29. $subject = $email_subject;
  30. /// remove slash - wrong preview
  31. if (get_magic_quotes_gpc()){
  32.     $subject = stripslashes($subject);
  33.     $content = stripslashes($content);
  34. }
  35. /*
  36. function mailque($dbconn, $email, $subject, $body, $headers) {
  37.     $body=SQLdecode($body);
  38.     $email=SQLdecode($email);
  39.     $subject=SQLdecode($subject);
  40.     $headers=SQLdecode($headers);
  41.    
  42.     $SQL = "insert into que (
  43.                             que_email,
  44.                             que_subject,
  45.                             que_body,
  46.                             que_headers
  47.                             )
  48.                             values
  49.                             (
  50.                             '$email',
  51.                             '$subject',
  52.                             '$body',
  53.                             '$headers'                                             
  54.                             )";
  55.  
  56.     if(!pg_exec($dbconn, $SQL))
  57.         echo "Error at ".$email."<br>";    
  58. }
  59. $dbconnmail = pg_connect("host=localhost port=5432 user=maillist dbname=maillist");
  60. */
  61. // editor staff replace
  62. $content=str_replace("http://".$HTTP_HOST.dirname($PHP_SELF)."/", "", $content);
  63. $content=str_replace("\\\"","\"",$content);
  64. $content=str_replace("&amp;","&",$content);
  65. $content=str_replace("/userimages/","http://".$HTTP_HOST."/userimages/",$content);
  66.  
  67. // special chars replace
  68. $content=str_replace("€","&euro;",$content);
  69. $content=str_replace("©","&copy;",$content);
  70. $content=str_replace("®","&reg;",$content);
  71. $content=str_replace("™","&#8482;",$content);
  72. $content=str_replace("’","'",$content);
  73. $content=str_replace("–","&#8212;",$content);
  74.  
  75. if($sent == 1) {
  76.     $subject;
  77.     if (!$id) {
  78.         $new_id = db_getid();      
  79.         $SQL = "insert into maillist_email(email_from, email_id, email_template, email_subject, email_html, email_images, email_name, email_date ) values ('".$email_from."',".$new_id.", $email_template, '".SQLDecode($email_subject)."', '".SQLDecode($contentReal)."','".SQLDecode($uploadedImages)."','".SQLDecode($email_name)."', '".date("Y.m.d h:i", strtotime("now"))."')";
  80.         db_exec($DB_LINK, $SQL);
  81.         $id = $new_id;
  82.     }
  83.     $SQLWHERE = " AND (";
  84.     for ($i = 0; $i < count($mlgroup); $i++)
  85.         $SQLWHERE .= ($i > 0 ? " OR " : "").db_concat(array("','", "maillist_group", "','"))." LIKE '%,".$mlgroup[$i].",%'";
  86.     $SQLWHERE .= ")";
  87.     if(count($mlgroup)){
  88.         $SQL = "select distinct UPPER(TRIM(maillist_email)) as mailtosend, max(maillist_name) as finalname from maillist where maillist_active=".db_set_boolean(true)." ".$SQLWHERE." group by mailtosend ";     
  89.         $RES1 = db_exec($DB_LINK, $SQL);
  90.         $NR=db_numrows($RES1);
  91.         for($br=0;$br<$NR;$br++){
  92.             if(checkEmail(db_result($RES1, $br, "mailtosend"))){
  93.                 $t = new Template("../email_templates", "remove");
  94.                 $SQL = "SELECT template_file FROM maillist_template, maillist_email WHERE email_id=".$id." AND email_template=template_id";
  95.                 $RS = db_exec(1, $SQL);
  96.                 $tf = db_result($RS, 0, "template_file");
  97.                 $t->set_file(array("page" => $tf));
  98.                 $t->set_var(array(
  99.                 "DATE" => date("F d Y", strtotime("now")),
  100.                 "NAME" => db_result($RES1, $br, "finalname"),
  101.                 "TITLE" => $subject,
  102.                 "BODY" => $content,
  103.                 "EMAILID"=> $id,
  104.                 "HOST" =>"http://".$HTTP_HOST,
  105.                 "DEAR" => $translator->translate("DEAR"),
  106.                 "Click_here" => $translator->translate("Click_here"),
  107.                 "removed_from_maillist" => $translator->translate("removed_from_maillist"),
  108.                 "Recomend_to_friend" => $translator->translate("Recomend_to_friend"),
  109.                 "EMAIL" => db_result($RES1, $br, "mailtosend")
  110.                 ));
  111.                 $t->parse("OUT", array("page"));
  112.                 $maillist_email =  $t->get_var("OUT");
  113.                 mail(db_result($RES1, $br, "mailtosend"), $subject, $maillist_email, "From: $email_from\nContent-Type: text/html;\n charset=utf-8;\n");
  114.                 //mailque($dbconnmail, db_result($RES1, $br, "mailtosend"), $subject, $maillist_email, "From: (".$email_from.")\nContent-Type: text/html;\n charset=utf-8;\n");
  115.             }
  116. if ($br>0 && $br%2==0) {sleep(15);}
  117.         }
  118.     }
  119.     if(checkEmail($email_to)){
  120.         $NR++;
  121.         $t1 = new Template("../email_templates", "remove");
  122.             $SQL1 = "SELECT template_file FROM maillist_template, maillist_email WHERE email_id=".$id." AND email_template=template_id";
  123.             $RS1 = db_exec(1, $SQL1);
  124.             $tf = db_result($RS1, 0, "template_file");
  125.             $t1->set_file(array("page" => $tf));
  126.             $t1->set_var(array(
  127.             "DATE" => date("F d Y", strtotime("now")),
  128.             "NAME" => $email_toname,
  129.             "TITLE" => $subject,
  130.             "BODY" => $content,
  131.             "EMAILID"=> $id,
  132.             "HOST" =>"http://".$HTTP_HOST,
  133.             "EMAIL" => $email_to
  134.             ));
  135.             $t1->parse("OUT", array("page"));
  136.             $maillist_email =  $t1->get_var("OUT");
  137.             mail($email_to, $subject, $maillist_email, "From: ($email_from)\nContent-Type: text/html;\n charset=utf-8;\n");
  138.     }
  139.     $resmessage = "Email Sent to ".($NR)." emails";
  140. }
  141.  
  142. // preview the email
  143. if($sent == 2){
  144.     $t = new Template("../email_templates", "remove");
  145.     $SQL = "SELECT template_file FROM maillist_template WHERE template_id=$email_template";
  146.     $RS = db_exec(1, $SQL);
  147.     $tf = db_result($RS, 0, "template_file");
  148.     $t->set_file(array("page" => $tf));
  149.     $t->set_var(array(
  150.     "DATE" => date("F d Y", strtotime("now")),
  151.     "NAME" => "Sir/Madam",
  152.     "TITLE" => $subject,
  153.     "BODY" => $content,
  154.     "HOST" => "http://".$HTTP_HOST,
  155.     "EMAIL" => ""
  156.     ));
  157.     $t->parse("OUT", array("page"));
  158.     $previewcontent =  $t->get_var("OUT");
  159.     echo $previewcontent;
  160. }
  161.  
  162. // update in db
  163. if($sent == 3) {
  164.     if($id){
  165.         $SQL = "update maillist_email set email_from='".$email_from."',email_template = $email_template, email_subject = '".SQLDecode($email_subject)."', email_html = '".SQLDecode($contentReal)."', email_images='".SQLDecode($uploadedImages)."', email_date = '".date("Y.m.d h:i", strtotime("now"))."', email_name = '".SQLDecode($email_name)."' where email_id=$id";
  166.         $resmessage = "Email Updated";
  167.     }else{
  168.         $SQL = "insert into maillist_email(email_from,email_id, email_template, email_subject, email_html, email_images, email_name, email_date ) values ('".$email_from."',".db_getid().", $email_template, '".SQLDecode($email_subject)."', '".SQLDecode($contentReal)."','".SQLDecode($uploadedImages)."','".SQLDecode($email_name)."', '".date("Y.m.d h:i", strtotime("now"))."')";
  169.         $resmessage = "Email Added";
  170.     }
  171.     db_exec($DB_LINK, $SQL);
  172. }
  173. db_close();
  174.  
  175. if($sent != 2 && $sent > 0){
  176. ?>
  177. <HTML>
  178.     <HEAD>
  179.     <link rel="stylesheet" href="style.css">
  180.     <TITLE>Message</TITLE>
  181.     </HEAD>
  182.     <BODY bgcolor="#ffffff">
  183.     <table height="100%" border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#000000">
  184.     <tr><td>
  185. <?
  186. echo "<center><h3>".$resmessage."</h3><br><br> <input type=button value='OK' onclick='window.close()'></center>";
  187. ?>
  188.     </td>
  189.     </tr>
  190.     </TABLE>
  191.     </BODY>
  192. </HTML>
  193. <?
  194. }
  195. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement