The mail function is an e-mail sending function provided by php. However, it is not as easy as a third-party plug-in the methods I tested. However, it has a feature that it is quick to use when the amount is small. In
The mail function is an e-mail sending function provided by php. However, it is not as easy as a third-party plug-in the methods I tested. However, it has a feature that it is quick to use when the amount is small.
When we use PHP to send emails, we do not need to use powerful tools such as phpmailer every time. we can find a good PHP mail encapsulation function on the Internet, this function can solve the following problems frequently encountered by using the mail () function:
1. how to send HTML-format emails.
2. garbled characters are entered in the subject of the email.
3. in addition to the recipient's email, the recipient must also have a name in Chinese.
4. the sender must enter the website name. when receiving the email, it is not a bald display email address. // Encode and convert the Chinese UTF-8 of the email address
- Function format_mail_address ($ address ){
- If (preg_match ("|", $ address, $ matches )){
- $ Name = mb_substr ($ address, 0, strpos ($ address ,'
- // Function usage:
- Html_mail (
- "E-Commerce salons ",
- Array (
- "User ",
- "User B "),
- "This is a test email ",
- "
Note that when the recipient is an array, one of the recipients can view the email addresses of all other recipients. If you want to send messages separately (the email addresses are invisible to each other), you can send them one by one in a loop. The encrypted CC address can be hidden.
-
- $ To = $ mailtoname. "<". $ mailtomail. "--> ";
- $ Mailsubject = "Mail test ";
- $ Mailheader = "X-Priority: 5n ";
- $ Mailheader. = "From:". "Sales Teamn ";
- $ Mailheader. = "X-Sender:". "support@ec-shalom.comn ";
- $ Mailheader. = "Return-Path:". "support@ec-shalom.comn ";
- // Normal cc email
- $ Mailheader. = "Cc:". $ mailcc. "n ";
- // Encrypted CC
- $ Mailheader. = "Bcc:". $ mailbcc. "n ";
- $ Mailbody = "e-commerce salon-mail () function to send emails ";
- $ Result = mail ($ to, $ mailsubject, $ mailbody, $ mailheader );
- Echo"
-
- Mail sent to ". "$ ". ""; echo $ mailsubject. ""; echo $ mailbody. ""; echo $ mailheader. ""; if ($ result) {echo"
-
- Email sent successfully!
- ";} Else {echo"
- Email cocould not be sent.
- ";}?>
Note that the php mail function requires server support. The configuration of this function is as follows:
Windows XP and 2000 have the SMTP server component function, but they are not installed yet. Select "Control Panel> add/delete Programs> add/delete Windows components". in the displayed "Windows component wizard" dialog box, double-click "Internet Information Service (IIS, the detailed selection option is displayed. select "SMTP Service" and press "OK" to insert the Windows XP installation disk for installation.
After the SMTP server is installed, select "Control Panel> performance and maintenance> Management Tools> Internet information service" to open the Internet information service settings window, and click the name of the local computer on the left side of the window, expand the local computer directory and you will see two branches, Wed site and default SMTP virtual server ". Right-click "default SMTP virtual server" and choose "properties" to open the "default SMTP virtual server properties" window.
The general tab mainly sets the IP address. click "127.0.0.1" in the drop-down list to point to the IP address of the local computer. use the default settings for other items. If you have a fixed IP address for LAN access, you should select the corresponding IP address.
On the "access" tab, set the access permission. Click "authentication" and select "anonymous access", which means that any user can send the message. you do not need to select the other two items; click "interrupt" in "connection" and "Middle limit" in "connection control", and select "except the following list" to allow access by all users.
On the "mail" tab, set the mail transmission conditions and restrictions. you can use the default values for "limit mail size" and other four options without changing them;
"Sending copies of the non-delivered reports to" can return the failed emails to the sender and indicate the reason for the failure; "dead letter directory" sets the location where emails that fail to be sent are stored.
Set the mail delivery time in the "transmission" option. you do not need to modify it here, but use the default value. The "LDAP route" option is used to specify the directory server ID and attribute used by the server, and you do not need to start it here.
The "security" option sets the authorized user to use the sending server. the default user is "Administrators". you can click "add" to add a user.
After everything is set up, you will support your email sending server!
After SMTP is installed, you should find PHP in WINDOW2K. The INI file is in C: WINNT.
Open and find the following lines
- [Mail function]
- ; For Win32 only.
- SMTP = 10.0.0.9 ------- replace it with your IP address. 10.0.0.9 is an even IP address :)
- ; For Win32 only.
- Sendmail_from = test@test.com --- sender information
Then restart APACHE.