Re: mail() in a loop?



Daniel wrote:
Hi, Paul,

Yes, you can have mail in the loop;

Personally I would first scan the database, build an array of email addresses and then start sending messages.

Also, sending the bunch of messages from php will be done synchronous, that means that who posted the message will have to wait till the messages are sent and THEN the browser will come back again.

Therefore I would suggest you another approach: try to decouple the process a little bit. Tomorrow you might have 1000 users - create the email messages in the loop, spool them on the hard drive in some folder (you have to do first some housekeeping) and then have a cron job who starts every 5 minutes pick the messages and send them.

Or exec to a mail program and run it in background..

Sendmail in fact doesn't send mail..immediately. It queues it. Then forks a process to deliver it.



Regards,
Daniel

"Paul Fredlein" <paulfredlein@xxxxxxxxxxxxxxx> wrote in message news:1iysc17.1plqfdt117ay0aN%paulfredlein@xxxxxxxxxxxxxxxxxx
Hi,

I have a simple discussion forum with about 100 members. When a new
topic is posted I would like to email all members to let them know of
the new post.

Can I have mail() in a loop? That is, select all from the mysql database
and loop through sending mail to each one. Any possible problems to look
out for? Should I wait for the mail() function to return before sending
the next? Should I put in a delay or something before sending the next?

Any help appreciated.

Thanks,

Paul


.



Relevant Pages

  • Re: extract items from list in single field
    ... Try using the Splitfunction to change the delimited string into an array. ... You would then loop through the members of the array and write one record to ...
    (microsoft.public.access.modulesdaovba)
  • Re: RunCommand acCmdRecordsGoToNext
    ... Another thing that may come in handy if that doesn't is to loop through the ... The database I am utilizing this ... increasing intRecordCount on each loop. ... Dim strPassword As String ...
    (microsoft.public.access.forms)
  • Re: Getting value from an array using another array
    ... If you show how you are accessing the members of p, ... You realise that is permanently modifying the array passed to the ... You can get rid of the not logic by re-arranging the loop: ... A little more robust, but not much. ...
    (comp.lang.javascript)
  • Re: Sql Connection
    ... ..i dont like the code either....again a example of a loop ... making calls to the database .... ... what i did yesterday is just get the parsed data to a temp table on the ... the question is the open connection where the Datareader is used insid ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inserting multiple records
    ... array of values, how would this go? ... > You can turn it into a single call to the database by constructing a union ... > dim sSQL, sUnion ... > 'start loop ...
    (microsoft.public.inetserver.asp.db)

Loading