Configure the SMTPmail service in XAMPP so that PHP's mail () function can send emails. The mail () function in PHP is very simple, but it also makes it impossible to use the popular SMTP server with verification function (gmail, 163,126, etc) now it is easy to configure the mail () function of sendmai PHP provided by XAMPP, but it also makes it impossible to use the popular SMTP server with verification function (gmail, 163,126, etc)
Now, by configuring sendmail provided by XAMPP, PHP's mail () function can send emails normally. the following example uses smtp.126.com:
1. find the xampp/php. ini file, find the [mail function] statement block, and modify it as follows:
1 [mail function]
2 SMTP = smtp.126.com
3 smtp_port = 25
4 sendmail_from = xxx@126.com
5 sendmail_path = "\" your xampp installation directory \ xampp \ sendmail \ sendmail.exe \ "-t"
2. find the xampp/sendmail. ini file and modify it as follows:
1 [sendmail]
2 smtp_server = localhost
3 smtp_port = 25
4 default_domain = 126.com
5 auth_username = your email address @ 126.com
6 auth_password = your password
7
8 force_sender = xxx@126.com
3. configure the SSL service (optional)
Because gmail and 163,126 require SSL to connect to the SMTP mail server, the sendmail program in xampp does not support ssl connection.
If you are using another mailbox and do not need SSL to connect to SMTP, you can change smtp.126.com to the corresponding SMTP server address.
We can download and install an SSL proxy software where we use http://www.stunnel.org/
After the installation is successful, open the stunnel. conf file in stunnel and find the following code and modify it as follows:
Here we add a [126-smtp] node:
1; [gmail-smtp]
2; client = yes
3; accept = 127.0.0.1: 25
4; connect = smtp.gmail.com: 465
5
6 [126-smtp]
7 client = yes
8 accept = 127.0.0.1: 25
9 connection = smtp.126.com: 465
4. test your PHP mail () function!
View source
Print? Www.2cto.com
01 02 $ from_name = 'XXX ';
03 $ from_email = 'XXX @ 126.com ';
04 $ headers = 'from: $ from_name <$ from_email> ';
05 $ body = 'This is a test mail ';
06 $ subject = 'Test email from php mail ()';
07 $ to = 'XXX @ xxx.com ';
08 if (mail ($ to, $ subject, $ body, $ headers )){
09 echo "success! ";
10} else {
11 echo "fail... ";
12}
13?>
5. You have succeeded!
Author: json
The Compile () Mail function is very simple, but it also makes it impossible to use the popular SMTP server with verification function (gmail, 163,126, etc.). now, by configuring sendmai provided by XAMPP...