Monday, 15 April 2013

php - mail() in foreach loop -



php - mail() in foreach loop -

mail() used send email users in array provided foreach loop. want set limit number of emails sent per hour. besides, need maintain track of how many emails sent , not sent ( ajax perchance ).

is there can set pause between time each email sent, other sleep()? coz stops whole script , not able track number of emails beingness sent.

code simple:

foreach ($user_emails $user_email) { if(mail( $user_email, $subject, $model->message, $headers)) { echo "sent </br>"; } }

advice on library great! :)

you can set mails want send in database, , execute cronjob/crontab open php file reads database , send x amount of emails. cronjob can configured run every minute, half hour, hour, etc, per requirement. in terms of load improve run cronjob more , send smaller amount of emails per execution, instead of running cronjob less , sending more mails @ same time.

of course, don't forget remove email record (or mark sent) db after running mail service command record, won't sent twice.

php email

No comments:

Post a Comment