Page 1 of 1

a problem with mailing

Posted: Wed Jun 15, 2005 7:54 am
by Pain
like I have this database with users and their e-mails, and every now and then i have to send them some mails (one-by-one). The problem is that there are 3 mails delivered to each user (sometimes 2 or 4). I think it could be because of the great amount of e-mails (if I send one or two e-mails everything is ok). Could anyone suggest a solution to this problem?

The code:

Code: Select all

<?php
$query=&quote;SELECT e_mail FROM users ORDER BY id&quote;;
$result=mysql_query($query);
while($row=@mysql_fetch_row($result))
       {
	mail($rowї0], $subject, $text, $headers);
	};
?>
d11wtq | Please use

Code: Select all

tags when posting PHP code[/color]

Posted: Wed Jun 15, 2005 7:58 am
by Syranide
put all user emails in an array, where the key is the email (also), looping through this list would only send an email to each once.

but in the first place, how could there be multiple of the same in the database?

EDIT: or you could add "DISTINCT" to your query, but that would only be a way of pushing the problem further away. so do NOT do this.

Posted: Wed Jun 15, 2005 8:07 am
by Pain
Syranide wrote:but in the first place, how could there be multiple of the same in the database?
there is no multiple data in the database. For a minute I thought that the problem could be related to multiple e-mail output from database, but I checked it and I can assure that every mail is sent only once (at least with the function mail()).

Posted: Wed Jun 15, 2005 8:10 am
by Syranide
something is apparently wrong with what you do, because to my knowledge mails don't send themselves (just as apples don't eat themselves).

I bet you are executing the entire scripts multiple times if you are sure that you are not sending more than 1 mail.

eitherway from what you've said, there is nothing we can help you with, post more code or explain much more indepth of where or what you think goes wrong and how you do it.

Posted: Wed Jun 15, 2005 8:17 am
by Pain
well... I think that the problem is that there are some 1000 or more e-mails to be sent. I think that when the server has to send 1000 e-mails one after another, the server just chokes. Maybe function usleep() would help? So the server can relax :lol: after every sent mail.

Posted: Wed Jun 15, 2005 8:18 am
by shiznatix
sounds like a good plan, try it out

Posted: Wed Jun 15, 2005 9:17 am
by CoderGoblin
Is the php file in question being "refreshed" before completion ?

It is often the case in situations like this where, as nothing is shown on the screen, a user presses reload, starting the mail run again.

Posted: Wed Jun 15, 2005 9:24 am
by Pain
CoderGoblin wrote:It is often the case in situations like this where, as nothing is shown on the screen, a user presses reload, starting the mail run again.
not in this case

p.s. I'd be happy if this were the problem