Sending a lot of e-mail (mailinglist-like)
Posted: Sat Aug 13, 2005 5:02 pm
This is what the client asks:
There are groups of people, each with an e-mail address. These can be mailed all together, or only a few at a time.
The total number of people will probably exceed 1000-1500. The messages that have to be sent are personal, so each one has a more or less personal subject or content (template-wise, replacing "Dear %NAME%" with the user's name for example).
This has to be realtime. The only technologies that I can use are PHP and MySQL. To send a 1000 messages takes up a lot of time, and the page that will be sending these messages will probably timeout before it reaches the end, so I came up with an, in my opinion, pretty clean solution, and a pretty crappy one too. I tried to make my own version of threading in PHP, since that is not possible.
I would like to present the user with a progress bar too. Staring at a blank page is pretty annoying.
1. Using AJAX
I create a JavaScript array with all the addresses, names, personal data I need in it, and loop over it, using xmlhttprequest to call a page called ie. mail.php. I can pass parameters etc and all mail.php will have to do is send one message.
This might work fine, but when I let the object terminate its task before the next iteration, the user's browser just hangs untill the last iteration, causing my progressbar to jump from 0 to 100%.
If I don't wait untill the object has finished before goin into the next iteration, it all goes too fast and not all messages are sent.
2. Using the image preloading in PHP
Since the solution above did not seem to work, I made a simple php file which returns a 1px gif, and let it preload 1000 times for example, each time called with a different parameter.
Problem here is browser caching. Some browsers seem to ignore my Cache-control header, and some messages are, again, not processed.
Now I know that all of this is a very bad idea, and that I should use specific software etc, but the client really wants it this way. I tried convincing him but... you all know the situation I think.
Can anyone help me out here? Either with a way to make AJAX useable in this case (altough it is kind of abusing this nice 'technology'), or with a better solution to my problem?
All help is really appreciated!
There are groups of people, each with an e-mail address. These can be mailed all together, or only a few at a time.
The total number of people will probably exceed 1000-1500. The messages that have to be sent are personal, so each one has a more or less personal subject or content (template-wise, replacing "Dear %NAME%" with the user's name for example).
This has to be realtime. The only technologies that I can use are PHP and MySQL. To send a 1000 messages takes up a lot of time, and the page that will be sending these messages will probably timeout before it reaches the end, so I came up with an, in my opinion, pretty clean solution, and a pretty crappy one too. I tried to make my own version of threading in PHP, since that is not possible.
I would like to present the user with a progress bar too. Staring at a blank page is pretty annoying.
1. Using AJAX
I create a JavaScript array with all the addresses, names, personal data I need in it, and loop over it, using xmlhttprequest to call a page called ie. mail.php. I can pass parameters etc and all mail.php will have to do is send one message.
This might work fine, but when I let the object terminate its task before the next iteration, the user's browser just hangs untill the last iteration, causing my progressbar to jump from 0 to 100%.
If I don't wait untill the object has finished before goin into the next iteration, it all goes too fast and not all messages are sent.
2. Using the image preloading in PHP
Since the solution above did not seem to work, I made a simple php file which returns a 1px gif, and let it preload 1000 times for example, each time called with a different parameter.
Problem here is browser caching. Some browsers seem to ignore my Cache-control header, and some messages are, again, not processed.
Now I know that all of this is a very bad idea, and that I should use specific software etc, but the client really wants it this way. I tried convincing him but... you all know the situation I think.
Can anyone help me out here? Either with a way to make AJAX useable in this case (altough it is kind of abusing this nice 'technology'), or with a better solution to my problem?
All help is really appreciated!