php mail无效,php中mail()不可用,php中sendmail不能用的解决方法

好多人在用php的mail()函数发送邮件时不成功,折腾半天也没找到什么问题。

我昨天也遇到这情况了,现在记录一下,以便以后再遇到这问题。

1:要用mail首先你要把sendMail扩展打开,我用的phpstudy,打开很简单,把勾打上就可以了。

a9ac3a43f3f3

2:然后打开php.ini然后搜索“[mail function]”,找到下面文本块,把我加红加粗的前面的;去掉,然后修改成你的邮件服务器,我用的163的,qq的比较麻烦,所以用的163。

sendmail_path="D:\phpStudy\tools\sendmail\sendmail.exe -t"

//这个后面的地址就是你的sendmail.exe的地址,如果你配置php环境时没有安装直接下载sendmail安装一下就可以了。

; For Win32 only.

; http://php.net/smtp

SMTP = smtp.163.com

; http://php.net/smtp-port

smtp_port = 25

; For Win32 only.

; http://php.net/sendmail-from

sendmail_from = intrwins@163.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").

; http://php.net/sendmail-path

; Force the addition of the specified parameters to be passed as extra parameters

; to the sendmail binary. These parameters will always replace the value of

; the 5th parameter to mail(), even in safe mode.

;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename

mail.add_x_header = On

sendmail_path="D:\phpStudy\tools\sendmail\sendmail.exe -t"

3:配置sendmail.ini

然后找到你的sendmail文件夹,找到sendmail.ini文件,搜索“[sendmail]”,配置相关信息。

a9ac3a43f3f3

4:同样的设置一下,看红色加粗部分POP3_这三个是设置接取邮件的配置,需要的也可以设置下,我们现在设置的是发送的配置。

smtp_server=smtp.163.com

; smtp port (normally 25)

smtp_port=25

; SMTPS (SSL) support

; auto = use SSL for port 465, otherwise try to use TLS

; ssl = alway use SSL

; tls = always use TLS

; none = never try to use SSL

smtp_ssl=auto

auth_username=****** //你的用户名

auth_password=**********    //你的邮件密码

; if your smtp server uses pop3 before smtp authentication, modify the

; following three lines. do not enable unless it is required.

pop3_server=

pop3_username=

pop3_password=

; force the sender to always be the following email address

; this will only affect the "MAIL FROM" command, it won't modify

; the "From: " header of the message content

force_sender=intrwins@163.com

5:重启你的php环境,然后再试试应该就可以了。

$to = "zzndc@qq.com";

$subject = "我就是在测试php的mail函数,请163别给我退回";

$message = "我就是在测试php的mail函数,请163别给我退回";

$from = "intrwins@163.com";

$headers = "From: $from";

if(mail($to,$subject,$message,$headers)){

echo "发送成功";

}else{

echo "发送失败";

}

?>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值