Home >Backend Development >PHP Tutorial >How to send email with PHP 2_PHP tutorial

How to send email with PHP 2_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:25:421166browse

mail([recipient], [subject], [mail body], [header]);
You simply replace [recipient] with the next name in the list. Assuming you already have one Array of email addresses:
$addresses = array("me@mycompany.com", "you@yourcompany.com", "someone@otherplace.com");
All you need to do is loop through array, get the new address and send the email.
If you have a list of email addresses in a database, the same principle applies: loop over them.
You already get the idea. Obviously, the same The concept will work for your specific database type and table structure, although the code will need to be modified a bit.
People seem to overlook something when looping through a list of addresses: if you have more than 50 address to be processed, your script will most likely time out before completing because PHP has a default time limit of 30 seconds for each script to run. You can change this time limit but be careful when doing so. Keep this This kind of modification is limited to specific scripts, such as scripts that iterate through an address list to send emails. Otherwise, you may personally overload the server's threads, and your computer will crash and never recover.
Set the time in the script To limit, you can use the set_time_limit() function. You can set a time limit, say 60 seconds (set_time_limit(60)), or you can let it run until it completes (set_time_limit(0)).
will Add this code to your script, and your email address loop will happily continue working until the email has been sent to all addresses in the list.
Sending HTML-formatted emails is also a seemingly difficult task. , something easy to do. Once you learn how to do it, you might kick yourself for thinking it was hard.
We need to make two changes to the email script we've already written :
Your email should be in HTML format.
You must add the content-type header.
That’s all you need to do. Have a recipient that can read HTML-formatted email clients You will see their email in a large, bold format. If you send an HTML email that includes an image tag, you must remember to use the full URL in the src attribute, for example: How to send email with PHP 2_PHP tutorial.


You should also remember that not everyone can read emails in HTML format and those who can't read this format can only see the HTML code itself. This is annoying, so it's better to think twice before sending it. .
Conclusion
You can use PHP to send email in any way, method or form imaginable. This tutorial only provides the basics: configure your server and send a simple email. You also You can send attachments with emails you generate using the mail() function, modify a bunch of different headers, and do anything else email client programs and mailing list sending programs can do.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532019.htmlTechArticlemail([recipient], [subject], [mail body], [header information]); You only Simply replace [recipient] with the next name in the list. Assuming you already have an array of email addresses...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn