Home > php教程 > php手册 > 配置PHP中的mail方法发送邮件

配置PHP中的mail方法发送邮件

WBOY
Release: 2016-06-06 19:58:25
Original
1222 people have browsed it

我的环境:XAMPP v3.2.1 准备工作 1.检查有没有sendmail程序,在xampp安装目录下的sendmail文件夹下。没有则下载sendmail.zip(http://glob.com.au/sendmail/),然后解压并放在在xampp目录下。 2.去mail.google.com注册一个google的邮箱,比如账号:user@gmai

Copy after login

我的环境:XAMPP v3.2.1

准备工作

1.检查有没有sendmail程序,在xampp安装目录下的sendmail文件夹下。没有则下载sendmail.zip(http://glob.com.au/sendmail/),然后解压并放在在xampp目录下。

2.去mail.google.com注册一个google的邮箱,比如账号:user@gmail.com,密码:passwd

配置步骤:

1.php.ini中如下设置:

; SMTP = localhost;

 smtp_port = 25;

sendmail_from = sendmail_path = "C:/xampp/sendmail/sendmail.exe -t"

也就是注释掉"SMTP"、"smtp_port"、"sendmail_from",设置sendmail_path变量的值为以上所示(根据自己电脑上sendmail.exe的目录自行设置)。

2.sendmail.ini中如下设置

smtp_server=smtp.gmail.com

smtp_port=587

smtp_ssl=TLS

error_logfile=error.log

debug_logfile=debug.log

auth_username=user@gail.com

auth_password=passwd

测试代码:

<?php $now = date("Y-m-d h:i:s");
$headers = 'From: name<sender@qq.com>';
$body = "hi, this is a test mail.\nMy email: sender@qq.com";
$subject = "test mail";
$to = "recver@qq.com";
if (mail($to, $subject, $body, $headers))
{
echo 'success!';
} 
else 
{
echo 'fail';
}
?>
Copy after login
以上代码执行后recver@qq.com 会收到发过来的邮件,但是邮件头中的sender@qq.com会被替换成user@gmail.com。
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template