学习日记-0129 php邮件发送
运行环境:XAMPP
准备工作:
1、检查有没有sendmail程序。具体步骤:在xampp安装目录下查看是否存在sendmail.exe,没有就建立文件夹sendmail,下载一个sendmail.zip(http://glob.com.au/sendmail/),放进去。
2、注册一个163邮箱,然后进行配置:
(1)php.ini 设置
SMTP=localhost;
smtp_port=25;
sendmail_from = sendmail_path =”C:/xampp/sendmail/sendmail.exe -t”。
3、配置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 (执行发送邮件的邮箱密码)
4、
使用代码测试
<?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';
}
?>