PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,035 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,277 people online right now. Registration is fast and FREE... Join Now!




Mail() 1000+ people problem

 

Mail() 1000+ people problem

nightscream

5 Nov, 2009 - 08:28 AM
Post #1

D.I.C Head
**

Joined: 4 Dec, 2008
Posts: 113



Thanked: 2 times
My Contributions
My client site has over 4000 members and he likes to have a mail function that mails all the users but the problem is it takes to long to send all the mails and after 360sec php gives error it taking to long but how can I make it work?



User is offlineProfile CardPM
+Quote Post


jaql

RE: Mail() 1000+ People Problem

5 Nov, 2009 - 01:04 PM
Post #2

D.I.C Head
**

Joined: 19 Oct, 2009
Posts: 59



Thanked: 5 times
My Contributions
Add this to the top of the script:
CODE
set_time_limit(0);


or maybe take a look at what the php doc says about the mail() function:
QUOTE

Note: It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.


This post has been edited by jaql: 5 Nov, 2009 - 01:07 PM
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Mail() 1000+ People Problem

5 Nov, 2009 - 01:38 PM
Post #3

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,890



Thanked: 139 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
If you really must use mail(), make sure that it is in a loop and sends between 30-100 emails per batch. Since your member count is pretty low, you should get it done in just a few loops.

Bare in mind that the loops should be after a page refresh.. So have a "Continue" link after it's done the first loop, then that link refreshes the page to continue with the next batch. How you handle this is completely down to you, a file/DB with remaining recipients could be a good method.
User is offlineProfile CardPM
+Quote Post

nightscream

RE: Mail() 1000+ People Problem

5 Nov, 2009 - 04:04 PM
Post #4

D.I.C Head
**

Joined: 4 Dec, 2008
Posts: 113



Thanked: 2 times
My Contributions
sounds good, something like refreshing the page.
So the pear mail option should be able to do this in one time?
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Mail() 1000+ People Problem

5 Nov, 2009 - 04:06 PM
Post #5

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,890



Thanked: 139 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
Yes, Mail_Queue sets up emails to send in the background using a cron script that will process a few messages every minute or so. It's effectively the same as calling mail and refreshing the page every now and then, but it doesn't require the browser to refresh obviously.
User is offlineProfile CardPM
+Quote Post

Jono20201

RE: Mail() 1000+ People Problem

6 Nov, 2009 - 02:55 PM
Post #6

D.I.C Head
**

Joined: 7 Jul, 2009
Posts: 65



Thanked: 1 times
My Contributions
I suppose if you wanted to be really fancy you could use ajax smile.gif

This post has been edited by Jono20201: 6 Nov, 2009 - 02:56 PM
User is offlineProfile CardPM
+Quote Post

nightscream

RE: Mail() 1000+ People Problem

8 Nov, 2009 - 12:10 PM
Post #7

D.I.C Head
**

Joined: 4 Dec, 2008
Posts: 113



Thanked: 2 times
My Contributions
yeah you're right I could use ajax but I don't really know that, not that much time to learn atm but I probably use the refresh thing.

Thank you!!

This post has been edited by nightscream: 8 Nov, 2009 - 12:11 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 08:40AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month