在Windows下利用php自带的mail函数发邮件

这几天看《Head First PHP & MySQL》,里面有发邮件的例子是用系统自带的mail函数发送的,自己照书上写的试了一直不成功,后来终于在网上找到解决方案,现在总结下。

我的开发环境是WAMP Server 2.4

关于php mail函数介绍 请看这里

Windows下用mail函数需要下载一个sendmail 点此下载

  • 解压到C:\wamp\sendmail
  • 配置sendmail.ini(我这里以126邮箱为例)
    • smtp_server=smtp.126.com
    • smtp_port=587
    • smtp_ssl=ssl
    • error_logfile=error.log
    • debug_logfile=debug.log
    • auth_username=你的用户名
    • auth_password=你的密码
    • force_sender=你的邮箱

     配置error.log和debug.log可以在sendmail目录下的error.log和debug.log查看相应的发送错误和情况。

  • 配置php.ini(文件位置类似于:C:\wamp\bin\apache\Apache2.4.4\bin),找到[mail function]
    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    ;SMTP = 
    ; http://php.net/smtp-port
    ;smtp_port = 25
    
    ; For Win32 only.
    ; http://php.net/sendmail-from
    ;sendmail_from = you@domain.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    ; http://php.net/sendmail-path
    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"

    上面的主要就是最后一句 sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"

  • 在Apache模块上要允许 “ssl_module”(网上找的好多文章都没有这一步,我自己试的时候一直因为这个不成功)

    

我写了这么一个测试页面

<?php

mail('mib23@126.com', 'test', 'test');

?>

好了,这样应该已经能发送了。

转载于:https://www.cnblogs.com/mib23/p/phpsendmail.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值