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.
AHMED SAMYownerAuthor Commented:
thanks i am now tring it
AHMED SAMYownerAuthor Commented:
is it right

require "connection.php";

	$sql="SELECT * FROM newsletter WHERE news_type=0";

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


		$sql="UPDATE newsletter SET news_type='sent' WHERE email='$emails' ";



Open in new window

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.
AHMED SAMYownerAuthor Commented:
thanks i will try it
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.