[PHP mail] Send mail to multiple users at once

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
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

[PHP mail] Send mail to multiple users at once

Post by thiscatis »

Hi!

Ok, is there a way to use the mail function to send the body of the mail to emails stored in a user table?
So the method:

1. select the email accounts from the user table and put them in an array
2. use the mail() function and select all the email accounts from the sql array
3. submit the mail so it will be sent to all the accounts from the table.

Greetings,
thiscatis
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yes.

Depending on the amount of e-mails, just loop through it (for or foreach).

If you're constantly doing hundreds and even thousands, you might consider breaking down the loop into sections of 100-150. Or there is also sending mail via sockets, which is a much more complex process than looping the mail() function.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Hi,

thanks for your reply.
It will be used for 50-100 mail accounts.
So shouldn't be a problem then I guess.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yeah, processing time isn't so bad with ~100 e-mails.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

For something like that I'd consider using a library like Swift.
Post Reply