sandbudd Posted September 24, 2008 Share Posted September 24, 2008 I have a php form that I can fill out and send to all the emails in the database. It works and the emails are sent out but at 65 emails that are in the database I get a CGI Time out error. Does anyone know how to work around this with code or other wise. Thanks in advance. <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <?php set_time_limit(0); ?> <?php $hostname = ""; $database = ""; $username = ""; $password = ""; $petitionscript = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db('',$petitionscript); ?> <? if (isset($_POST['submit'])) { $subject = $_POST['subject']; $message = $_POST['message']; $query="SELECT Email FROM signature"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $email=mysql_result($result,$i,"Email"); mail($email, $subject, $message, "From: admin<[email protected]>\nX-Mailer: PHP/" . phpversion()); echo "Email sent to: " . $email . "<br />"; $i++; } } ?> <br /> <form name="email" action="<?=$_SERVER['email.php']?>" method="post"> Subject <br /> <input name="subject" type="text" size="50" id="subject"><br /><br /> Message <br /> <textarea name="message" cols="50" rows="10" id="message"></textarea> <br /><br /> <input type="submit" name="submit" value="Email!"> </body> </html> Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/ Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 Uhh, do you use free hosting? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649832 Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 if your database is too big, I'd recommend having a script that stores "to be sent" e-mails in the DB, and cron it every 5 minutes. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649835 Share on other sites More sharing options...
sandbudd Posted September 24, 2008 Author Share Posted September 24, 2008 no I do not have free hosting Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649836 Share on other sites More sharing options...
sandbudd Posted September 24, 2008 Author Share Posted September 24, 2008 jonsjava could you tell me or show me how to do this? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649838 Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 too in-depth to tell you. You're going to need to code a script that executes, exactly like yours, but instead of looking at what you have posted, it looks at a table in the database. If the database is empty, it closes. If it's not, it runs until complete, then empties the table, then closes. CRON is a method of running scripts/applications at set intervals. This way, it's not running on Apache's time, it's running in the background. Apache is what sets the timeout. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649844 Share on other sites More sharing options...
sandbudd Posted September 24, 2008 Author Share Posted September 24, 2008 another quick question if someone has entered a bogus email address could that cause it as I see one and it worked okay the other day? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649848 Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 depends on how long your server waits for a failed timeout. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649856 Share on other sites More sharing options...
sandbudd Posted September 24, 2008 Author Share Posted September 24, 2008 took out the bad email and it didn't make any difference. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649864 Share on other sites More sharing options...
sandbudd Posted September 24, 2008 Author Share Posted September 24, 2008 could someone point me to a place or an example for what jonsjava said or point me in another direction please Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649886 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 put this at the top of your script, $maxtime is in seconds... The better solution is to run this via cron job where there is no time limit for executing scripts. <?php ini_set(max_execution_time,$maxtime); Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649966 Share on other sites More sharing options...
sandbudd Posted September 25, 2008 Author Share Posted September 25, 2008 Do I put the time in there someplace? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649969 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 Yes, as I said $maxtime is in seconds. <?php $maxtime = 1000; //or however many seconds you want/need ini_set(max_execution_time,$maxtime); Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649972 Share on other sites More sharing options...
sandbudd Posted September 25, 2008 Author Share Posted September 25, 2008 lol...sorry about that had a brain fart....will try Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649979 Share on other sites More sharing options...
sandbudd Posted September 25, 2008 Author Share Posted September 25, 2008 set it t0 100000 and it still timed out Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649985 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 Then as suggested above the timeout is your HTTP server and there's nothing you can do about that from php. You would need to change the server timeout, like if it is apache edit the httpd.conf. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-649993 Share on other sites More sharing options...
sandbudd Posted September 25, 2008 Author Share Posted September 25, 2008 found these files? MMHTTPDB asp 2.57 Kb MMHTTPDB js 24.40 Kb MMHTTPDB php 4.41 Kb adojavas inc 9.97 Kb mysql php 12.78 Kb would one of these be it? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-650008 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 No. You most likely won't be able to change the setting unless you own the server. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-650021 Share on other sites More sharing options...
sandbudd Posted September 25, 2008 Author Share Posted September 25, 2008 Would you be able to direct me to a tutorial or explain to me how to do the CRON? Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-650026 Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 sure, google "php cron" Do you have the ability through your server to setup cron jobs? If not it would be pointless to explain. Link to comment https://forums.phpfreaks.com/topic/125681-mass-email/#findComment-650036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.