Jump to content

Recommended Posts

Hi all

I wrote a system that will allow sending an email to a list of users (Currently 2935 users)

 

It takes the names of everyone in the list unless they opted out and sends the mail

then is supposed to notify who it sent to.

 

Here is the problem,

It works fine when I tested it with 7 users

All 7 emails were sent and the page displayed the 7 email address it sent it to.

but when I ran it with the full database

the page sat there for a while (Because of so many emails - I get that part) but eventually came up with a page cannot be displayed  page

No errors or anything and according to the tracking

All 2935 emails were delivered.

The 2nd email template sent - well I hit refresh when the page cannot be displayed  came up and it sent the mail twice.

 

I have read to use the PEAR Mail for large lists but Im honest - I have no idea how to even use that when I go to their page???

 

And I tried an example of adding sleep that I saw somewhere but that didnt do anything

I never even got the message saying it was taking a break So I am not sure I did that right.

 

So is there anything I can do to this existing code to solve the page cannot be displayed

 

 

 

 

if (isset($_POST['submitted'])) { // Check if the form has been submitted.

// Validate.	
	if (!empty($_POST['mail'])) {
	$m = escape_data($_POST['mail']);
} else {
	echo '<p><font color="red">You forgot to select a template!</font></p>';
	$m = FALSE;
}


if ($m) { // If everything's OK.

$query1 = "SELECT emess_mess, emess_title FROM maillist WHERE emess_id='$m'";		
$result1 = @mysql_query ($query1); // Run the query.
while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$em = $row1['emess_title'];	
$query = "SELECT * FROM mailer WHERE mail_receive='Yes'";		
$result = @mysql_query ($query); // Run the query.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$to = $row['mail_email'];
$sent = date("D M j Y - g:i a");	
$message = "Sent - $sent <br /> \n";
$message .= "If you cannot view this email, visit <a href=\"http://www.website.com\">website by clicking here</a></p>  \n";
$message .= $row1['emess_mess'];

$subject = $em;


// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: '.$to.'' . "\r\n";
$headers .= "From: website\r\nReply-To: [email protected]";

// Mail it
    $query3 = "INSERT INTO sent (title, sent_to) VALUES ('$em', '$to')";		
$result3 = @mysql_query ($query3); // Run the query.

$mail_sent = @mail($to, $subject, $message, $headers);



    
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent to $to <br />" : "Mail failed to $to <br />";
}//end message while

}//end to while

include ('./includes/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
			echo '<p><font color="red">We could not send the mail</font></p>'; 
		}	



}//end if submitted

 

Here is the sleep code I tried

set_time_limit(0);
// Lets send 100 emails at a time, with a 3 minute break

$wth = 100; // how many emails to send at a time

$sent = 0; // emails sent

$select = mysql_query("") or die(mysql_error());
while($x = mysql_fetch_array($select))
{ 

$sent+1;
// add one to the sent count

    if( $sent == $wth )
    {
        
        sleep( 300 );
        echo "Taking a break for 3 minutes..";
        $sent = 0;
// reset the sent count to 0
    }

mail();
// put your mail function here

 

Link to comment
https://forums.phpfreaks.com/topic/131071-another-newsletter-question/
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.