Hi,

I would like to send email messages to some 250 users using php. The addresses are stored in a mysql database.

I wanted to do something like

$result=mysql_query("SELECT email FROM people");

while ($myrow = mysql_fetch_array($result)) {

mail( ... )

}

However when the number of emails to send goes over 100, this takes ages, times out, etc.

Is there any software written especially to solve this problem?

Thanks, Kenneth.

    You could switch smtp servers. You don't mention what you're using but if it's sendmail then you can do better. (Whether it's worth the trouble of switching is another story.)

    You could try putting multiple recipients in an email (or use cc: or bcc🙂

    That's all I got.

      Try adding all of the to addresses together seperated by a space and then just use the mail() function once.

      $user_list="";

      $result=mysql_query("SELECT email FROM people");

      while ($myrow = mysql_fetch_array($result)) {

      $user_list .= $user_list . $myrow["email"] . " ";

      }

      mail( $user_list, $subject, $message );

        The best way to do a mailing list is when you click send emails...

        ...it will popup a small window that will send one email at a time then reload with a querystring called email and the value of the email just sent. then the script reads which email its just sent, marks it as sent, gets the next email.

        so the process would be
        - send first email
        - reload page(using the onload="") with email value
        - check email as sent
        - send next email
        - reload page
        - and the cycle continues...

        hope that helps its does with my site!

        Thanks, Phil G


        Free web hosting
        http://digital-avatar2.com

          Is sending by sendmail difficult in php ?

          I\'m kind of newbies in php and perl...

            [Chris] Try adding all of the to addresses together

            [Ken] You could try putting multiple recipients in an email (or use cc:

            A caution is in order here. Unless all 250 users already know each other, you will quite likely endure a large amount of hostility (and rightly so!) for passing around everybody's email address. And even if they do, who wants to read an email where the header goes on for 60+ lines of addresses?

            Darren is probably right (do this with Perl) but you certainly can implement a solution in PHP that works better, by talking directly to the SMTP server (which is after all what I would do in Perl anyway.)

            (1) Open a socket to the mail server and say HELO.

            (2) Write your from address using MAIL FROM:

            (3) Write the list of recipients using RCPT TO:

            (4) Write the visible headers and then the body in a DATA section.

            And yes, if your mailserver collapses under a message to only 250 addresses, it is certainly time for a better mailserver. Just upgrading to postfix might suffice.

              kirk, you know of any robust free to cheap mail servers in the world that would work well with php?

              thanks,
              blue

                Hi,

                Can you please drop us a code. That's a super example. But I just don't know how to put it in practice. Can you share that with us please?!!I just wanna see it in action. Please.

                  • [deleted]

                  Ehm.. there are faster and easier methods of sending lots of emails.
                  Especially if it's a standard email, you do not want to do that via a webserver.

                    Did I already mention postfix? Didn't I?.....
                    It's free, it's robust, it performs better than sendmail, it's a "drop-in" replacement for sendmail. No, it's not what you need for extremely high-volume mailing lists, but how many of us really are engaged in that?

                      sorry.. postfix didn't really sound like a stand alone product. more like a bug fix for a product I'd missed out one somewhere in the conversation. ill check it out. thx

                      blue

                        You avoid the hostility problem by using bcc:

                          Hope you've found a way to do this by now, but if not...
                          I recently wrote a php script which sends ~2500 emails automatically via a cron operation. It retrieves email addresses from our database and produces an individual email for each one based on assaciated details (preferred language, info they require etc) and cc's to related addresses. The plain script times out at about 55 messages, so what I did was recursively redirect passing all required info, the key here is to pass a progress indicator variable so the script knows where to begin again from and to test that that progress indicator has not exceeeded the number of emails to be sent and to bail out if it has (we don't want any infinite redirects do we?). This will work so long as you do no outputs to screen before the redirect (follow the rules in the php manual), I get it to email me with progress reports for each batch and then print a finished message when all mesages have gone

                          So in short, get the total number of addresses, get your first batch, create message and do mailing for each address (count each for progress indicator), test that your progress has not exceeded your total number (bail out if yes, i.e. stop script), if not then do redirect passing all necessary variables and progress indicator, repeat process using next batch until finished

                          phew! (I had to work around our cron redirect limit, but that's another equally long and boring story)

                            I did mine almost the same way.

                            I created a temp database to hold the message, then send the newsletter out in groups of 10, then refresh to send out the next, passing the variables of message on and total messages on in the URL. I do need to let the computer run the program though.

                            I send out almost 8000 addresses.

                            I send 1500 out in one shot in another newsletter/script, but it wouldn't work with the other list.

                            Bob

                              a year later

                              Hey, Kirk...could you explain a little more in depth how to go about doing this. Im researching some ways to send out large amounts of emails for a client site we are working on. I've never used php before in the way that you are suggesting. I would appreciate any more guidance you can offer. Thanks.

                                Write a Reply...