i need to send emails using interval way

i need to send emails using interval way

i have email list i need to Periodically send email to this list 70 email in hour

how i can do
AHMED SAMYownerAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
Assuming you are going to run the script from a cron job you can then vary the number of emails sent using the sleep()

Issue a sleep(50) after each email to force the script to wait 50 seconds before sending the next email. 70 emails will take 3500 seconds which is 100 seconds short of an hour. If you set your cron Job to run on the hour you should be in the ball park.

Also use set_time_limit() to ensure your script does not timeout.
After sending each email call set_time_limit(120) to ensure the server does not stop your script due to a timeout.
0
 
AHMED SAMYownerAuthor Commented:
thanks i am now tring it
0
 
AHMED SAMYownerAuthor Commented:
is it right

require "connection.php";

	$sql="SELECT * FROM newsletter WHERE news_type=0";
	$query=mysqli_query($conn,$sql);
	
	while($row=mysqli_fetch_array($query)){
		
		set_time_limit(20);

		$emails = $row['email'];
		
		$to = $emails;
		$subject = "****";
		$txt = "*******";
		$headers = "From: *****";

		mail($to,$subject,$txt,$headers);

		$sql="UPDATE newsletter SET news_type='sent' WHERE email='$emails' ";
		$query=mysqli_query($conn,$sql);

		sleep(55);
	}	
	


?>

Open in new window

0
 
Julian HansenCommented:
I would change the set_time_limit(20) to set_time_limit(60) - in other words more than your sleep time. You could also bring the set_time_limit() outside the loop as set_time_limit(3600)

Other than that the script should be fine.
0
 
AHMED SAMYownerAuthor Commented:
thanks i will try it
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.