PHP mail()

greg's picture

He has: 1,581 posts

Joined: Nov 2005

PHP mail() function
Is this acceptable to use for sending up to 10 emails with the same data in the same script?

I know it opens/closes server mail connections each time so is not efficient for large volumes, but what's a realistic threshold for this?

They have: 121 posts

Joined: Dec 2008

Speaking as someone who has never had to run a PHP script that sends mail on anything but the machines I admin myself - and so can only upset myself, I think ten is absolutely reasonable.

How is that for a disclaimer?!

The threshold might depend on the outgoing mail handler available locally to PHP. For instance, I typically configure to allow 25 simultaneous local SMTP 'sessions'. If you are consistently saturating the available connections - that wouldn't be a good thing.

Cheers,
Shaggy

greg's picture

He has: 1,581 posts

Joined: Nov 2005

It's a public form that will email however many times the form is being used by X visitors.

Hmm, so potentially more than 10.

What's a good alternative? Only need something simple to send some basic form text/tick box results etc.

They have: 121 posts

Joined: Dec 2008

So, filling a form results in a piece of email being produced?
If that is the case and you run into walls without getting help from your provider, it is time to find a new one. I can't think of anything much more legitimate than a form triggering the creation of an email...

(assuming of course, the form is secured enough that it doesn't become a spam gateway...)

Cheers,
Shaggy.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I don't see a problem with it. If you don't want to open and close a connection every time, you can put the TO field as the email addresses separated by commas:

<?php
mail
('[email protected], <a href="mailto:[email protected]">[email protected]</a>, [email protected]', 'Subject', 'Body', 'FROM: [email protected]');
?>

I think that would work.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

If you have multiple address in the To field, then all those address are visible to all the recipients, wich is not a good idea.'

I don't think sending them out separately is a bad idea when only doing 10.

greg's picture

He has: 1,581 posts

Joined: Nov 2005

It's likely to be less than 10 emails per form submitted anyway.

But as it's public, and submitting the form initiates a potential 5-10 emails per form submitted (i.e. per user using the form), is this still ok if multiple people use it simultaneously all day.

I don't think this will be the case, and probably more realistically a few users per hour, but I'm just considering potential future eventualities.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.