Mail ([recipient], [subject], [email subject], [header information]);
You only need to replace the [receiver] with the next name in the list. Suppose you already have an array of email addresses:
$ Addresses = array ("me@mycompany.com", "you@yourcompany.com", "someone@otherplace.com ");
All you need to do is traverse this array cyclically, get a new address, and then send this email.
If you have a list of email addresses in the database, the same principle applies: traverse them cyclically.
You have understood the essentials. Obviously, the same concept applies to your specific database type and table structure, although the code will need to be modified.
When people traverse an address list in a loop, they seem to ignore one point: if you have more than 50 addresses to process, your script may time out before it is completed, because PHP has a default time limit of 30 seconds for running each script. you can modify the time limit, but be careful when doing so. this modification should be limited to a specific script, for example, traversing a script for sending emails in the address list. otherwise, you may manually overload the server thread and your computer will crash.
To set a time limit in the script, you can use the set_time_limit () function. you can set a time limit, for example, 60 seconds (set_time_limit (60), or you can keep it running until it completes (set_time_limit (0 )).
After you add this code to your script, your email address traversal cycle will continue to work happily until the email is sent to all the addresses in the list.
It also seems difficult to send HTML-format emails. once you learned how to do this, you may kick yourself because you thought it was hard.
We need to make two modifications to the email script we have prepared:
Your email should be in HTML format.
You must add the content-type header.
This is all you need to do. the recipient with an email client that can read the HTML format will see their emails in large, bold format. if the HTML-format email you send includes image placement, you must remember to use the complete URL in the src attribute, for example: .
You should also remember that not everyone can read emails in HTML format, and those who cannot read this format can only see the HTML code itself. This is annoying, so it is best to think twice.
Conclusion
You can use PHP to send emails in any way, method, or any form you can imagine. this tutorial only provides the basic knowledge: Configure your server and send simple emails. you can also send attachments along with emails generated by using the mail () function to modify a lot of different header information, there are also other tasks that can be done by the email client program and the mail list Sender program.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service