Hey all,

I need to use the PHP mail() function in order to send an email to a number of individuals.

So lets say that I have 5 users that need to get a particular email. I was thinking that the correct way of going about using the mail() function, would be:
1) to create an array variable

2) load the 5 usernames in the array

3) then store in a variable the size of the array, i.e. in my example it is 5 positions.

4) make a for loop with its limit whatever the array size is...

5) for each iteration read the corresponding username from the array and use the mail() function to email that specific username...

The point is, does anyone know of any other function other than mail() that can take more than one recipients? That would be really helpful and actually it would be more optimal and save server time... I created a massml() function myself and it takes as recipient an array argument, it works with the specifications that I gave above. But I am using a loop inside my function so this is still the same as looping the mail() function... It's not much of a problem but the optimality of this has been bugging me since morning.

Thanks for listening, I appreciate any answers,

George

Recommended Answers

All 4 Replies

You can specify BCC addresses in the mail function, but that way would not allow you to send personalised emails..

As far as I am aware, mail would be the best way to do this.

Hey.

You should check out PHPMailer or Swift Mailer.
Both are much easier to deal with than the PHP mail function, and both allow for multiple recipients.

But if you don't want that, the steps you describe for you mail script looks OK. At least on paper :)

As an afterthought...
The mail function does allow for multiple recipients for one call.

If you pass something like User1 <user1@example.com>, User2 <user2@example.com> as the first parameter, the mail would be sent to both recipients.

See the to parameter description and example #4 in the manual.

As an afterthought...
The mail function does allow for multiple recipients for one call.

If you pass something like User1 <user1@example.com>, User2 <user2@example.com> as the first parameter, the mail would be sent to both recipients.

See the to parameter description and example #4 in the manual.

Hmmm, yeah, thanks for the link to the spec! So cool, no loops or anything needed, also I could store the recipients as a string var resulting from an array maybe... I should try this in the morning when I wake up, as this would allow for automatically populating the recipients!

Thanks, I'll check in the morning as I said and get back at this!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.