I need to know the limit of the mail function and current servers ?
The mail function itself has no limit, but some hosting providers limit the number of messages you can send in the case of shared hosting, i.e. multiple clients on the same server.
How many emails at a time can I send ?
The main limit is the running time. There is usually a 30-second limit, but you can remove the limit with the set_time_limit(0) function. However, some hosting providers are not allowed to use this function.
What to do to not overload the server ?
Depends on how you want to send it. In general the sending of email does not cause overhead in terms of CPU usage because it only requires process or network communication with servers, and as this is only I/O (input and output) operations do not consume CPU.
What consumes the most CPU is the composition of the messages themselves. What happens is that email patterns require you to properly encode messages in MIME format.
This means that for example 8-bit characters (letters with accents and cedillas) should be encoded in the body of the message using quoted-printable encoding, which you are not doing in the above example.
From PHP 5.3 there is integrated in PHP the function quoted_printable_encode. It’s much faster and simpler than trying to encode text with PHP routines as needed in previous versions.
Besides, I don’t recommend that you re-invent the wheel and try to do it manually as you did in your email composition example. There are many classes ready to do this that know how to compose messages according to Internet email standards. You don’t need to learn all patterns to use these classes.
I use the class MIME message which is even optimized for bulk email sending. I have a website that sends around 5 million newsletters a month. Some newsletters go by email to over 400,000 subscribers.
This class has caching capabilities to reuse connections equal composed messages sent to different recipients.
On the iMasters website there is a more detailed article explaining how the bulk PHP email sending using smart optimizations with this class.
Advantages of installing SMTP on the localhost and local SMTP limits ?
In this question you assume that you need an SMTP server to send messages. That’s not true. It’s a common misconception. I’ll try to explain without going into too much technical detail.
SMTP is a protocol for receiving messages. Who receives is the SMTP server. You only need an SMTP server if you need to receive messages.
In PHP to send email on a Linux system, the mail function uses a local program called sendmail that injects the message into the local email server.
The message is queued at the email server and later the email server sends the message communicating with the target SMTP server of the recipient’s email domain.
Therefore PHP itself does not use SMTP on Linux. PHP uses SMTP on Windows because normally Windows does not come with the mail server and so PHP needs to communicate with an SMTP server of its provider that is usually on another machine.
Some websites use external email services such as Amazon or Mailchimp because the hosting provider does not install local email server or offer SMTP server to delegate message delivery.
However these services get very expensive when you exceed the limits of free accounts, which seems to be your case.
In your case, I recommend installing a local email server, postfix or qmail type, not to have to pay high email accounts.
Note that when I say local email server, I am referring to an email server on your hosting machine, not on your personal computer that you have at home or at your company.
If you don’t have an email server installed, you may need a virtual server plan (VPS) or dedicated server to install if your hosting provider does not provide a.
However, you need to be careful to set up your domain’s TXT SPF record so that messages are not considered spam. You also need to be careful if you use an external SMTP server.
If you have questions about this, you can comment below, or create a new question.
Check your hosting to see how many emails/hours can be sent.
– rray