a problem with mailing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pain
Forum Newbie
Posts: 8
Joined: Wed Jun 15, 2005 7:42 am
Location: Riga, Latvia

a problem with mailing

Post 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]
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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.
Pain
Forum Newbie
Posts: 8
Joined: Wed Jun 15, 2005 7:42 am
Location: Riga, Latvia

Post 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()).
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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.
Pain
Forum Newbie
Posts: 8
Joined: Wed Jun 15, 2005 7:42 am
Location: Riga, Latvia

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

sounds like a good plan, try it out
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Pain
Forum Newbie
Posts: 8
Joined: Wed Jun 15, 2005 7:42 am
Location: Riga, Latvia

Post 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
Post Reply