PHP mail () function usage and configuration method

Source: Internet
Author: User
Tags html tags ini

have been using a Third-party mail system to send mail, such as QQ Ah, Gmail Ah, etc., but sometimes customers do not want to give us the sender's mailbox and password, then I found that the use of PHP with the mail function can fully achieve this demand


工欲善其事, its prerequisite. First, let's take windows as an example to illustrate how to configure local mail.

Download Attachment

-Extract to any path, modify Sendmail.ini, modify the following information as needed.

The code is as follows:





auth_username=*** @qq. com


force_sender=*** @qq. com


[Mail Function]


Smtp_port = 25

Sendmail_from = * * * @qq. com

Sendmail_path = "D:/sendmail/sendmail.exe-t-I."

Mail.add_x_header = On


The current test is only QQ sent success, 163 of the unsuccessful may be he has a filtering system, can be successfully sent to Gmail.


Copy code code as follows: Mail (to,subject,message,headers,parameters)

Definitions and usage

The mail () function allows you to send e-mail directly from a script.

Returns True if the post of the message was successfully received, otherwise false.


In messages specified in the message parameter, the rows must be separated by an LF (n). No more than 70 characters per line.

(under Windows) when PHP connects directly to the SMTP server, if a period is found at the beginning of a line, it is deleted. To avoid this problem, replace a single period with two periods.

The code is as follows:


$text = Str_replace ("N.", "N..", $text);


Tips and comments

Note: You need to remember that mail delivery is accepted and does not mean that the message arrives at the intended destination.


An official example of sending an HTML message is cited below.

The code is as follows:


$to = ",";

$subject = "HTML email";

$message = "

<title>html email</title>


<p>this Email contains HTML tags!</p>













When you send an HTML e-mail message, always set the Content-type

$headers = "mime-version:1.0". "RN";

$headers. = "Content-type:text/html;charset=utf-8". "RN";

More headers

$headers. = ' From: <> '. "RN";

$headers. = ' '. "RN";

Mail ($to, $subject, $message, $headers);


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.