Is There a Limit When Using PHP Mail Function

Limits for mail() function

PHP itself is perfectly capable of sending millions of emails/day. scripting language is of not much importance: there shouldn't be much difference either you are using PHP, Perl or Ruby, the limiting factor will be your mail server and perhaps network throughput (shouldn't affect you that much as you're saying you're not doing mass emailing). Answering your question directly - no - PHP doesn't not set a limit on amount of emails you can send. Also - server has nothing to do with emais, - so that doesn't limit you either.

I can tell you right away: if you can only add 1 To address and 1 BCC address - problem would be either in your MTA or email constructed incorrectly, not in PHP mail().

Is your BCC correct?, should look like this:

Bcc: user@example.com, anotheruser@example.com\r\n

or

Bcc: User <user@example.com>, Another User <anotheruser@example.com>\r\n

AFAik, on windows you can only do that:

Bcc: user@example.com, anotheruser@example.com

Also - SMTP RFC (RFC 5321) does not impose any limit on BCC field length, though some ISP may limit it intentionally to prevent spamming.

p.S> For large mailing lists - look at either: PHPmailer, swiftmailer, Zend_Mail.

Does php mail has any limit (Number of mails per day) or php mail function

PHP does not have a limit.

To set a limit, you have to define a wrapper for the sendmail command in php.ini

 sendmail_path = /usr/local/bin/wrapper-to-sendmail

on a server basis. I do have such wrapper code, but I understand that this is not your question here.

You can also fix a quota per directory in the above script using the environment variable PWD.

Maximum number of email addresses used in $to parameter when sending PHP mail?

Most web hosting companies will limit you to about 100 (per hour I believe). Check with your host.

How to limit sending email 90 per hour using php code?

You can use PHP to do it in this very hackish way:

Create a blank file called count_offset.txt
This will be a file that tracks the offset of the chunked set of 90 users.

Create another blank file called count_emails.txt
This will be a file that tracks the number of emails sent in the particular hour.

The PHP script that runs the email function (thru cron) can then open up this first text file to check which chunked set has been sent, and sends to the next set of users. It can check the second file for the 90 email limit.

For example:

$userCount = getNumberOfUsers(); // Whatever query you may have that counts how many total users there are.

$numChunks = ceil($userCount/90); // How many different groups to send the email.

$chunkFile = fopen('chunk_offset.txt', 'r+'); // Loads the file as resource.
$currentChunk = fread($chunkFile, filesize('chunk_offset.txt')); // Load the contents of chunk_offset.txt into variable.
$currentChunk = ($currentCount == '' ? 0 : (int)$currentChunk); // Load 0 if contents of file blank.

$countFile = fopen('count_emails.txt', 'r+'); // Loads the file as a resource in variable $countFile.
$currentCount = fread($countFile, filesize('count_emails.txt')); // Load the content of the file into variable $currentCount.
$currentCount = ($currentCount == '' ? 0 : (int)$currentCount); // If the value of $currentCount is blank, then sets it to integer 0, otherwise sets the variable as the integer value of file contents.

if ($currentCount <= 90) // Test the variable to see if it's under the limit. If it's under, send the email.
{
foreach ($whateverUserListYouHave as $integerKey => $emailAddress) // Iterating through whatever array of users you have.
// Hopefully index number => email, but the index number is important.
// Also, consistent ordering of the list of users is important.
// Remember, you can always create your own counter.
{
// The magic:
// You're testing for set of people who fall within the current chunk.
if ($integerKey >= ($currentChunk * 90) && $integerKey < ($currentChunk * 90 + 90))
{
send_email($emailAddress); // Whatever arbitrary email function you have here.
}
}
}

$currentCount++; // Iterate up the count.
fwrite($countFile, $currentCount); // Write the new count into the file.

if ($currentChunk == $numChunks) // If the current chunk number hits the total number of groups of 90, then reset the file to blank...
{
$currentChunk = '';
}
else if ($currentChunk < $numChunks) // ... Otherwise iterate up and let it hit the next chunk on the next hour.
{
$currentChunk++; // Iterate up the chunk.
}
fwrite($chunkFile, $currentChunk);

Afterwards, write another cron that clears the count_emails.txt file every hour (or turns the contents to 0). This other cron can run another PHP script or can be a Bash command if you prefer.

Here would be the cron if you wanted to do it using Bash commands:

0 * * * * cat /dev/null > count_emails.txt

The above line when added to cron, with use cat to clear the contents of the count_emails.txt file.

Cheers, and good luck!

How much mail() function can be used in 30sec execution time?

The php max_execution_time setting is customizable. 30 seconds is the default but you can set it to 0 seconds for no execution time limit at all. Use set_time_limit().

set_time_limit(0);

If you do this, you should be able to send all your email.

Please be careful about sending more than one email to the same mail server per second. You don't want to get blacklisted.

Why shouldn't I use PHP's mail() function?

Quoting:

Disadvantages of the PHP mail() function

In some cases, mails send via
PHP mail() did not receive the
recipients although it was send by WB
without any error message. The most
common reasons for that issue are
listed below.

  • wrong format of mail header or content
    (e.g. differences in line break
    between Windows/Unix)
  • sendmail not
    installed or configured on your server
    (php.ini)
  • the mail provider of the
    recipeint does not allow mails send by
    PHP mail(); common spam protection

Errors in the format of header or
content can cause that mails are
treated as SPAM. In the best case,
such mails are transfered to the spam
folder of your recipient inbox or send
back to the sender. In the worst case,
such mails are deleted without any
comment. If sendmail is not installed
or not configured, no mails can be
send at all.

It is common practice by free mail
provider such as GMX, to reject mails
send via the PHP function mail(). Very
often such mails are deleted without
any information of the recipient.

How can I send thousands of emails without limits in php?

If you run your own server and send legitimate emails, there is no practical limit to how many emails you can send. You're not paying per-message fees, and almost all spam filtering is now done by what the users do with their messages - so if they act like you're sending stuff they want (i.e. they read it and don't mark it as spam), you will have no deliverabilty issues.

There's nothing to say that a server sending high volumes of email will necessarily get blacklisted, though it is often regarded as suspicious if a new server suddenly starts sending lots of messages, so it's a good idea to ramp it up slowly, and/or spread your sending across multiple IPs.

I have self-built sites that send high volumes using PHPMailer - sometimes millions per day each - but you may have trouble configuring an off-the-shelf server to do that. PHP is quite capable of sending several hundred messages per second, mostly depending on your templating system.

You do have to be completely paranoid about your config though:

  • Set up strict SPF
  • Sign with DKIM
  • Configure DMARC
  • You can't use BCC for personalised messages
  • Don't send attachments
  • Keep messages small, link to bigger content
  • Make sure your mail server DNS records resolve both ways
  • Make sure you have good bounce handling (difficult in PHP)
  • Use VERP addressing (helps bounce handling)
  • Monitor your mail server queues
  • Deal with any unsubscribes, spam reports or blacklisting immediately
  • Always, always use double-opt-in for new subscriptions
  • Never use bought-in lists

All this stuff is essentially what you're paying for when you use an ESP, and though they will often try to tell you otherwise, there's nothing stopping you from doing it all yourself - as the saying goes, it's free so long as your time has no value!

As others have mentioned, RSS or notifications may allow you to reduce the amount you need to send via email.



Related Topics



Leave a reply



Submit