Jump to content

Recommended Posts

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<info@email.com>\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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.