Jump to content

Email in mass


ibnclaudius

Recommended Posts

I made a script to send 10 emails every 30 seconds to different recipients, but sometimes it fails, stops while sending, doesn't send all...

 

<?php

include('config.php');

$getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'";
$getUser_not_sent = mysql_query($getUser_sql_not_sent);

$i = 0;

while ($row = mysql_fetch_array($getUser_not_sent)) {
$emailUser = $row['email'];
$emailFrom = "from@from.com";
$emailSubject = 'subject';
$emailVerify = "url.php?email=" . $emailUser;
$emailBody = "<a href = \"$emailVerify\">link</a>";
$emailHeaders = "From:" . $emailFrom ."\r\n";
$emailHeaders .= "MIME-Version: 1.0\r\n";
$emailHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$emailHeaders .= "X-Priority: 3\r\n";
if (mail($emailUser, $emailSubject, $emailBody, $emailHeaders)) {
	mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'") or die (mysql_error());
	$i++;
}
if ($i == 10) {
	sleep(30);
	$i = 0;
}
}
exit;

?>

 

What should I change?

Link to comment
https://forums.phpfreaks.com/topic/247866-email-in-mass/
Share on other sites

How I would implement this:

 

ini_set('max_execution_time', 60);

 

on this?

 

<?php

include('config.php');

$getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'";
$getUser_not_sent = mysql_query($getUser_sql_not_sent);

$i = 0;

while ($row = mysql_fetch_array($getUser_not_sent)) {
$emailUser = $row['email'];
$emailFrom = "from@from.com";
$emailSubject = 'subject';
$emailVerify = "url.php?email=" . $emailUser;
$emailBody = "<a href = \"$emailVerify\">link</a>";
$emailHeaders = "From:" . $emailFrom ."\r\n";
$emailHeaders .= "MIME-Version: 1.0\r\n";
$emailHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$emailHeaders .= "X-Priority: 3\r\n";
if (mail($emailUser, $emailSubject, $emailBody, $emailHeaders)) {
	mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'") or die (mysql_error());
	$i++;
}
if ($i == 10) {
	sleep(30);
	$i = 0;
}
}
exit;

?>

 

Link to comment
https://forums.phpfreaks.com/topic/247866-email-in-mass/#findComment-1272792
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.