Solve a few problems often encountered using the mail () function

Source: Internet
Author: User
In our usual use of PHP to send mail, not every time need to use a powerful tool like Phpmailer, found on the internet a good PHP mail encapsulation function, the function can solve the following using the mail () function frequently encountered several problems

1. How to send HTML-formatted messages.

2. The mail subject is garbled in Chinese.

3. In addition to the recipient's mail, but also to fill in the name, but also in Chinese.

4. The sender is required to fill in the name of the site, so that when the person receives the message is not bare display email address. UTF-8 encoding Conversion of e-mail address in Chinese

function Format_mail_address ($address) {     if (Preg_match ("| |", $address, $matches)) {       $name = mb_substr ($ Address, 0, Strpos ($address, '  ///function:  html_mail ("       e-commerce",       Array (           "User A",           "User B"),       " This is a test message ",  "

The point to note is that when the recipient is an array, one of the recipients views the message and sees all the other recipients ' e-mail addresses. If you want to send them separately (you can't see each other's email addresses), you can use loops to send them one by one. You can use the encrypted CC method to implement a hidden encryption cc email address.

<?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 ";   General CC message  $mailheader. = "CC:". $MAILCC. " n ";   Encrypt cc  $mailheader. = "Bcc:". $MAILBCC. " n ";   $mailbody = "E-commerce-mail () function sends 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 be sent. </strong>      <strong> ";}?&gt;</strong>

Note that the PHP mail function requires the support of the server, which is configured as follows:

Windows XP and 2000 own the functionality of the component SMTP server, but it is not generally installed. Select Control Panel → add/Remove Programs → add/Remove Windows Components, pop up the Windows Components Wizard dialog box, in which you double-click the Internet Information Services (IIS) entry, open the detailed selection, select SMTP Service, press OK, Insert the Windows XP installation disk for installation

After the SMTP server is installed, select control Panel → performance and maintenance → administrative tools →internet Information Services open the Internet Information Services Settings window, click the local computer name on the left side of the window, expand the Local machine directory, and you can see that there are two branches of "Wed site" and " Default SMTP virtual server. Open the Default SMTP Virtual server Properties window by right-clicking on the default SMTP virtual server and selecting Properties.

The General tab primarily sets the IP address, click the IP Address drop-down key to select "127.0.0.1", which means pointing to the local computer IP address, and other items using the default. If you are a LAN access and have a fixed IP address, then the IP address should select the appropriate address

The Access tab, set access permissions. Click Authentication, select Anonymous access, which means that any user can send, two other items are not selected; Click Break in connection and middle limit in connection control, and select only the list below to indicate that access is allowed to all users.

The Mail tab sets the message transmission conditions and restrictions, and four options, such as "limit message size to", can use the default values without changing ;

"Send a copy of the non-delivery report to" to return the unsuccessful message to the sender and indicate the reason for the failure; The Badmail directory setting does not send the location where a successful message was sent.

The transport option sets the message delivery time, which is not modified here, uses the default value, and the LDAP routing option is used to specify the directory server identity and attributes used by the server, and there is no need to start it.

The "Security" option sets the user with the right to use the sending server, the default user is "Administrators", and you can click "Add" to add the use user.

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

After the SMTP is installed you should be under WINDOW2K, you find PHP. INI file under C:winnt

Open to find the following lines

[Mail Function]

; For Win32 only.

SMTP = 10.0.0.9-------"Replaced by your ip,10.0.0.9 is the IP of the I:)

; For Win32 only.

Sendmail_from = test@test.com---"Sender information

Then restart Apache.

Related Article

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.