Configure SMTP mail service under XAMPP so that PHP's mail() function can send emails_PHP tutorial

WBOY
Release: 2016-07-13 17:51:41
Original
1388 people have browsed it

PHP’s mail() mail function is very simple, but it also makes it impossible to use currently popular SMTP servers with verification functions (gmail, 163, 126, etc.)
Now by configuring the sendmail provided by XAMPP, PHP's mail() function can send emails normally. The following takes: smtp.126.com as an example:
1. Find the xampp/php/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 xamppsendmailsendmail.exe" -t"
2. Find the xampp/sendmail/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@126.com
6 auth_password = your password
7
8 force_sender = xxx@126.com
3. Configure SSL service (optional)
Because gmail, 163, 126, etc. need to use SSL to connect to the SMTP mail server, and the sendmail program in xampp does not support SSL connections.
If you are using another mailbox and do not need SSL to connect to SMTP, just change smtp.126.com to the corresponding SMTP server address.
We can download and install an SSL proxy software, we use http://www.stunnel.org/
After the installation is successful, open the stunnel.conf file in stunnel, 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 connect = smtp.126.com:465
4. Test your PHP mail() function, haha!
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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478161.htmlTechArticlePHP’s mail() mail function is very simple, but it also makes it impossible to use the currently popular SMTP with verification function. Servers (gmail, 163, 126, etc.) are now configured via sendmai provided by XAMPP...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template