Using the PHP mail function to deliver a mailbox

Source: Internet
Author: User
Tags format message win32

When we normally use PHP to send mail, we don't always need to use a powerful tool class like Phpmailer, and find a nice PHP mail encapsulation function on the Internet that solves several problems that are frequently encountered using the mail () function
1. How to send an HTML format message.
2. The subject of the mail is filled with garbled Chinese.
3. The recipient, in addition to filling in the recipient's mail, also has to fill in the name, but also in Chinese.
4. The sender should fill in the name of the website, so that when the person received the message is not bare display mail address. UTF-8 Code Conversion of email address in Chinese


function Format_mail_address ($address) {
if (Preg_match ("| |", $address, $matches)) {
$name = mb_substr ($address, 0, Strpos ($address, '
How to use the function:
Html_mail (
"Electric Business Salon",
Array
"User A",
"User B"),
"This is a test email,"

The point to note is that when a recipient is an array, one of the recipients viewing the message sees the e-mail address of all other recipients. If you want to separate to send (each other can not see their own e-mail address), you may use the loop to send one by one. You can use the encrypted cc to implement the e-mail address where the encrypted CC is hidden.

<?php
$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 Mail
$mailheader. = "Cc:". $MAILCC. " n ";
Encrypt cc
$mailheader. = "BCC:". $MAILBCC. " n ";
$mailbody = "Shang Sharong-mail () function to send mail";
$result = Mail ($to, $mailsubject, $mailbody, $mailheader);
echo "

Mail sent to "." $to. " ” “; Echo $mailsubject. ” “; Echo $mailbody. ” “; Echo $mailheader. ” “; if ($result) {echo

<strong></strong><strong>email sent Successfully!</strong>

<strong> "; }else{echo "</strong>

<strong></strong><strong>email could not to be sent. </strong>

<strong> "; }?&gt;</strong>


Note that the PHP mail function requires support from the server, and this function is configured as follows

Install set up service side


Windows XP and 2000 itself have the functionality of the component SMTP server, but are not generally installed. Select Control Panel → add/Remove Programs → add/Remove Windows components, pop-up The Windows Components Wizard dialog box, double-click the Internet Information Services (IIS) entry, open the detailed selection, select SMTP service, press OK, Insert a Windows XP Setup disk for installation


After installing the SMTP server, select the control Panel → performance and maintenance → Administrative tools →internet Information service to open the Internet Information Services Settings window, click the local computer name on the left side of the window, expand the local computer directory, and see two branches of "Wed site" and " Default SMTP virtual server. Right-click on the default SMTP virtual server to select Properties to open the Default SMTP Virtual server Properties window.


The General tab mainly sets the IP address, click the IP address dropdown to select "127.0.0.1" to point to the IP address of the local computer, and the other items use the default. If you are a LAN access, have a fixed IP address, then the IP address should choose the appropriate address



Access tab, set access permissions. Click "Authentication", select Anonymous access, which means that any user can send, the other two do not have to choose, click "Disconnect" in connection control and section limit, select "except the list below" to indicate that access to all users can be allowed.


On the Mailings tab, set the message transfer conditions and restrictions, and the four options, "limit message size to", can use default values and need not be changed;


"Send a copy of an unsent report to" returns the sender with an unsuccessful message, stating the reason for the failure; The Badmail directory setting does not send a location where successful messages are stored.


The transport option sets the message delivery time, where you do not need to modify it, use the default value, and the LDAP routing option to specify the directory server identity and properties used by the server, and do not need to start it here.


The security option is set up to use the sending server's authorized user, the default user is "Administrators", and you can click Add to add the user.


After everything has been set up, you have embraced your own mail-sending server!

SMTP installed after you should be under WINDOW2K, you find PHP. INI file under C:winnt
Open to find the following lines
[Mail Function]
; For Win32.
SMTP = 10.0.0.9-------"Replaced by your ip,10.0.0.9 is my IP:)


; For Win32.
Sendmail_from = test@test.com---"Sender information


And then restart Apache

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.