Configure the SMTP mail service in XAMPP so that PHP's mail () function can send emails

Source: Internet
Author: User
Tags ssl connection stunnel

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, 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 <? Php
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

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.