Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] mass mail - time out
Forum PHP.pl > Forum > Przedszkole
andrzejek
Problem polega na tym, i¿ przy wysy³ce oko³o 1050 e-mails, ale podzielonych na paczki, nastêpuje "time out" i e-mail nie zostaje wys³any. Niestety nie wiem co, je¶li idzie o serwer trzeba wzi±æ pod uwagê aby unikn±æ tego problemu. Wszelkie uwagi, bêd± bardzo pomocne. Konto jest na unixie do wysy³ki u¿ywam klasy PHPMailer.

Ka¿da wskazówka bardzo mile widziana.

Oto kod w pliku (plik najpierw zapisuje e-news jako plik html, potem wysy³a pocztê ze skrótem informacji oraz z dodatkow± informacj± z bazy danych):

  1. <script type="text/javascript">
  2. var counter=0;
  3. function insRow()
  4. {
  5. counter++;
  6. var x=document.getElementById('tblEntry').insertRow(document.getElementById('tblEntry').rows.length)
  7. var y=x.insertCell(0)
  8.  
  9. var row = "<td><p>Title: <input name="title[" + counter + "]" type="text" size="42" />";
  10. row += "</p><p>Article Bookmark (max12 characters, NO SPACES): ";
  11. row += "<input name="anchor[" + counter + "]" type="text" size="18" ";
  12. row += "maxlength="12" /></p><p>Short Introduction (max 225 characters): ";
  13. row += "<input name="intro[" + counter + "]" type="text" size="38" ";
  14. row += "maxlength="255" /></p><p>Article:<br /><textarea name="article[" + counter + "]" ";
  15. row += "cols="75" rows="10" ></textarea></p><hr></td>";
  16.  
  17. y.innerHTML=row;
  18.  
  19. //z.innerHTML="<input type='text' name='title[" + counter + "]'/>";
  20. //alert(counter);
  21. //alert(z.innerHTML);
  22. //var arr = document.getElementById('myTable').rows
  23. //alert(document.getElementById('myTable').rows.length - 1);
  24. }
  25.  
  26. function delRow() {
  27. if (counter>0) {
  28. var x = document.getElementById('tblEntry').deleteRow(document.getElementById('tblEntry').rows.length-1);
  29. counter--;
  30. }
  31. }
  32. </script>
  33. <h2>Create And Mail Newsletter</h2>
  34. <?php
  35.  
  36. $emailsent=false;
  37.  
  38. if (isset($_POST['submit'])) {
  39. $query = "SELECT
  40. DISTINCT coursetypeid FROM courses c
  41. WHERE
  42. startdate>CURDATE()
  43. AND
  44. startdate <= DATE_ADD(CURDATE(),INTERVAL 90 DAY)
  45. ORDER BY
  46. c.coursetypeid";
  47.  
  48. $result = getRecords($query);
  49. $arrCourseTypes = array();
  50. for ($i=0;$i<count($result);$i++)
  51. $arrCourseTypes[$i]=$result[$i][0];
  52.  
  53. $courselist = "";
  54.  
  55. for ($i=0;$i<count($arrCourseTypes);$i++) {
  56.  
  57. //get courses for the coursetype
  58. $ctid = $arrCourseTypes[$i];
  59.  
  60. //add coursetype name to the courselist
  61. $courselist .= "<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
  62. <strong>" .getCoursetypeName($ctid) . "</strong>:<br>";
  63.  
  64. $query = "SELECT
  65. courseid,c.coursetypeid,
  66. DATE_FORMAT(c.startdate,'%e %b %Y') as sdate, city, coursetypename
  67. FROM
  68. courses c, coursetypes ct,hostagency h
  69. WHERE
  70. c.coursetypeid=ct.coursetypeid
  71. AND
  72. c.hostagencyid=h.hostagencyid
  73. AND
  74. startdate>CURDATE()
  75. AND
  76. ct.active='yes'
  77. AND
  78. startdate <= DATE_ADD(CURDATE(),INTERVAL 90 DAY)
  79. AND
  80. c.coursetypeid = $ctid
  81. ORDER BY
  82. startdate";
  83.  
  84.  
  85. //get the records
  86. $result = getRecords($query);
  87.  
  88. //loop through the records
  89. foreach ($result as $course) {
  90. $courselist .= $course['sdate'] . " - " .$course['city'] . "<br>";
  91. }
  92.  
  93. // add link
  94. $courselist .= "<a href="http://www.ccaa-outreach.com/list_coursedates.php?coursetypeid=$ctid">
  95. See course calendar >></a></font></p>";
  96. }
  97.  
  98. //build the newsletter linklist
  99. $linklist='';
  100. $today = getdate();
  101. $month = (strlen($today['mon'])<2)?"0".$today['mon']:$today['mon'];
  102. $day = (strlen($today['mday'])<2)?"0".$today['mday']:$today['mday'];
  103. $datestamp = $today['year'] . $month .$day;
  104. $newsletterurl="http://www.ccaa-outreach.com/newsletter_display.php?nldate=$datestamp";
  105.  
  106. //a variable to hold the newsletter text
  107. $newsletter = "<h1>CCAA Newsletter - " . date("F dS, Y") . "</h1>";
  108.  
  109. for($i=0;$i<count($_POST['title']);$i++) {
  110.  
  111.  $linklist .="<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>" .
  112.  $_POST['title'][$i] . "</strong> <br><strong>" . $_POST['intro'][$i] ."</strong><br>" .
  113. "<a href="$newsletterurl#" . $_POST['anchor'][$i] .
  114. "">more information >></a></font></p>";
  115.  
  116. //add text to the newsletter file
  117. $newsletter .= "<a name='" . $_POST['anchor'][$i] . "'></a><h2>" .
  118. stripslashes($_POST['title'][$i]) . "</h2><p>" .
  119. stripslashes($_POST['intro'][$i]) . "</p><p>" .
  120. stripslashes($_POST['article'][$i]) . "</p>";
  121.  
  122. }
  123.  
  124. //save the newsletter to file
  125. $filename = "/var/www/html/newsletters/newsletter_" . $datestamp .".htm";
  126.  
  127. //open the file for writing
  128. $fp = fopen($filename,"w");
  129.  
  130. if ($fp) {
  131. if (!fwrite($fp,$newsletter)) {
  132. echo "There were some problems with writing to file.
  133. Please contact the web master.";
  134. }
  135. } else {
  136. echo "Couldn't open the file. Please contact the web master.";
  137. }
  138.  
  139.  
  140. //get the template
  141. $htmlfile = file_get_contents("newsletter.htm");
  142.  
  143. $htmlfile = str_replace("%courselist%",$courselist,$htmlfile);
  144. $htmlfile = str_replace("%linklist%",$linklist, $htmlfile);
  145.  
  146. $html = true;
  147. $subject = "CCAA Newsletter";
  148.  
  149. //build the emails array
  150. $query = "select email from newsletter";
  151. $result = getRecords($query);
  152. $arrEmails = array();
  153. for ($i=0;$i<count($result);$i++)
  154. $arrEmails[$i]=$result[$i][0];
  155.  
  156. if (!sendNewsletter($arrEmails, $subject, stripslashes($htmlfile), $html)) {
  157. echo "There were some problems with sending this newsletter. Please contact the w
    eb administrator";
  158. } else {
  159. echo "Mail sent.";
  160. $emailsent=true;
  161. }
  162. //print_r($_POST);
  163. //echo $newsletter;
  164. }
  165.  
  166. if (isset($emailsent) && $emailsent==false) {
  167. ?>
  168.  
  169. <P><input type="button" onclick="insRow()" value="+">
  170. <input type="button" onclick="delRow()" value="-"></P>
  171. <form method="post" id="form" name="form">
  172. <table border="0" cellspacing="0" cellpadding="4" id="tblEntry">
  173. <tr>
  174. <td><p>Title:  <input name="title[0]" type="text" size="42" /></p>
  175.  
  176. <p>Article Bookmark (max12 characters, NO SPACES):
  177. <input name="anchor[0]" type="text" size="18" maxlength="12" />
  178. </p>
  179. <p>Short Introduction (max 225 characters):
  180. <input name="intro[0]" type="text" size="38" maxlength="255" />
  181. </p>
  182. <p>Article:<br />
  183. <textarea name="article[0]" cols="75" rows="10" ></textarea>
  184. </p><HR>
  185. </td>
  186. </tr>
  187. </table>
  188. <p>
  189. <input id="submit" type="submit" value="  Send Newsletter  " name="submit" />
  190. </p>
  191. </form>
  192. <?php
  193. } else {
  194. echo $htmlfile;
  195. }


Dziêkujê
Andrzej
treewood
Wyjsc znam kilka i niektore nie sa za dobre:
- uzyj mail() moze pare maili pojdzie szybciej w tym czasie
- wrzuc do header'a maila BCC: adres, adres2, adres 3 i powinno wyslac wszystko za jednym razem
- odpal w cron'ie mailing i niech wysyla co np. 10-20 minut jakas porcje po kilkadziesiat maili
Go¶æ
Niestety na tym serwerze nie mam dostepu do 'cron jobs'. Z podpowiedzi wnioskuje, ze lepiej jest wysylac przez BCC: niez przez TO:?

Dziekuje za podpowiedzi.

Andrzej
nasty
to bylo na forum. nawet kilka razy.

http://forum.php.pl/index.php?showtopic=48469
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.