Email 2_php Tutorial with PHP

Source: Internet
Author: User
The Mail () function is very simple: there are only five parameters, and two of them are optional. These parameters are: Receiver address subject Letter content Other file information header (optional) additional configuration options for the SMTP service (optional) added header parameters control such as CC, BCC, Mail features such as reply-to, or other features that follow the SMTP protocol. In this example, I only use the From and reply-to information headers. If you want to email me but you are using a non-Windows system, the program code should look like this: If you are using a Windows-based SMTP service, then you may not need to use the fifth parameter, and in the additional header information parameters (that is, the fourth parameter), you need to write them separately-use instead. So, The same message is sent through the Windows-based SMTP service with the following code: The Echo statement in the script causes your Web browser to display a message to you when the script is finished. If you do not write the Echo statement, you will get an "Empty file" dialog box because no output can be sent to the browser side. The Mail () function returns the true value as long as it is able to connect to the specified SMTP server. But this does not mean that the message was successfully reached by the receiver. The mail () function does not wait or report the success/error code sent by the SMTP server. The mail () function may return false values and then give you a warning "cannot connect, on line X" or "Unknown error, on line x." If any of these two messages appear, you should check the SMTP values in the php.ini. There are two possible causes for these messages: the SMTP server is down, or PHP is unable to connect to it. Either way, your mail cannot be sent out. This script uses hard-coded values for these parameters. With a simple HTML form, you can insert values into these parameters and have a good feedback form. Once you know how to send a person an email, you may not be able to press the same email to many recipients-just like a news letter. All this involves a nice, lightweight loop that iterates through a list of recipients and sends them to them. The Mail function is the same in the same way: Mail ([ Receiver], [subject], [message body], [header information]); You simply need to replace [receiver] with the next name in the list. Suppose you already have an array of e-mail addresses: $addresses = Array ("me@mycompany.com", "you@yourcompany.com", " Someone@otherplace.com "); All you need 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 your database, the same principle applies: loop through them. You already know the ropes. Obviously, the same concept applies to your particular database type and table structure, although the code needs to be changed. People seem to overlook a point when iterating through an address list: If you have more than 50 addresses to process, your script will probably time out before it finishes. 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. To limit this modification to a specific script, such as a script that traverses an address list to send a message. Otherwise, you may be able to overload the server's thread, Then your computer will crash and never be. To set the time limit in the script, you can use the Set_time_limit () function. You can setSet the time limit, say 60 seconds (Set_time_limit (60)), or you can make it run straight until it is complete (set_time_limit (0)). Add this code to your script, and your email address traversal loop will continue to work happily until the message is sent to all the addresses in the list. Sending an HTML-formatted e-mail message is also an easy thing to look at. Once you've learned how to do it, you might kick yourself because you thought it would be difficult. We need to make two changes to the e-mail script we have written: your email should be in HTML format. You must add the Content-type header information. That's all you have to do. A recipient who can read the HTML-formatted e-mail client will see their message in large, bold format. If you send an HTML-formatted 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 can read an HTML-formatted e-mail message and those who cannot read it can only see the HTML code itself. This is annoying, so it's better to think twice. Conclusion you can use PHP to send e-mails in any way, in any way, or in any form imaginable. This tutorial just provides basic knowledge: Configure Your server and send simple messages. You can also send attachments along with e-mails that you generate with the mail () function to modify a whole bunch of different header information, There are also things that you can do with any email client program and mailing list sender program.

http://www.bkjia.com/PHPjc/531947.html www.bkjia.com true http://www.bkjia.com/PHPjc/531947.html techarticle The Mail () function is very simple: there are only five parameters, and two of them are optional. These parameters are: Receiver address subject Letter content Other file information header (optional) SMTP Service 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.