How to email with PHP (2)

Source: Internet
Author: User
Tags array format message mail time limit client

Mail ([receiver], [subject], [mail subject], [header information]);

You simply 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 have to do is loop through the array, get the new address, and then send the message.

If you have a list of e-mail addresses in the database, the same principle applies: iterate through them.

You've learned the ropes. Obviously, the same concept is true for your particular database type and table structure, although the code will need to make some changes.

People seem to overlook the point of looping through an address list: If you have more than 50 addresses to deal with, your script will probably time out before it's done, Because PHP has a default time limit of 30 seconds for each script to run. You can modify this time limit but be careful when doing so. Limit this change to a specific script, such as traversing a script that sends a message to an address list. Otherwise, you might be able to overload the server's threads with your own hands, Then your computer will crash and never be the same.

To set a time limit in your script, you can use the Set_time_limit () function. You can set a time limit, say 60 seconds (Set_time_limit (60)), or you can keep it running straight through it (set_time_limit (0)).

Add this code to your script, and your email address traversal loop will work happily until the message is sent to all the addresses in the list.

Sending HTML-formatted emails is also an easy thing to do. Once you've learned how to do this, you may be kicking yourself because you thought it was hard.

We need to make two changes to the mail script we've written:

Your email should be in HTML format.
You must add Content-type header information.

This is all the things to do. A recipient who can read an HTML-formatted e-mail client will see their mail with a large, bold-format letter. If you send an HTML format message that includes an image label, you must remember to use the full URL in the SRC attribute, for example:
You should also remember that not everyone is able to read HTML-formatted emails and those who can't read this format can only see the HTML code itself. It's annoying, so it's better to think twice.

Conclusion
You can use PHP in any way, method or any form imaginable. This tutorial simply provides the basics: Configure your server and send a simple message. You can also send an attachment to an e-mail message that you create with the mail () function to modify a whole bunch of different header information. There are things you can do with any email client program and mailing list sending program.



Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.