php email发送失败的解决办法:1、在php.ini里配置好适当的smtp服务器地址和端口信息;2、借助sendmail程序发送邮件。
本文操作环境:linux5.9.8系统、php7.1版,dell g3电脑
php email发送失败怎么办?
php发送邮件错误
warning: mail() [function.mail]: failed to connect to mailserver at "localhost" port 25, verify your "smtp" and "smtp_port" setting in php.ini or use ini_set() in
解决方法:
php的mail函数使用的是smtp服务发出e-mail的。也就是说你需要在php.ini里配置好适当的smtp服务器地址和端口信息。如果你需要在本机上发出e-mail,即
smtp = localhostsmtp_port = 25
这样的话,你需要在你自己的本机上配置上smtp服务才可以。你可以尝试打开iis的smtp服务。
说明一下,php中的mail()函数要借助sendmail程序发送邮件,而sendmail -t -i一般是linux/unix系统的自带程序,而windows系统没有这个程序,所以就不能直接利用mail()函数发邮件了。
实现在windows下利用mail()发送电子邮件
1、发送邮件系统要有smtp服务。在“windows server 2003”下安装“smtp service”组件:
a、“添加删除windows组件”->“应用程序服务器”->“internet 信息服务(iis)”点击“详细信息”。
b、选择“smtp service”进行安装。
2、对smtp进行设置:
a、打开“internet 信息服务(iis)管理器”,找到“默认 smtp虚拟服务器”。
b、在该服务上单击右键选择“属性”。
c、在弹出的“默认 smtp虚拟服务器 属性”框内点选“访问”表项,选择“身份验证”按钮。
d、在弹出的“身份验证”框内只选择“匿名访问”其它都不选。
e、回到“访问”表项,选择“中继”按钮,在弹出的“中继限制”框内单击“添加”按钮,添加127.0.0.1的ip地址。
3、修改“php.ini”:
------------------------------
[mail function]; for win32 only.smtp = localhostsmtp_port = 25; for win32 only.sendmail_from = me@example.com
------------------------------
4、运行本程序,登陆“$toaddress”所示邮箱查看邮件。
$toaddress = 'xuzhang@mascatv.com';$subjects = 'test the php mail';$mailcontent = 'onlu test the php mail!';$fromaddress = 'from: me@localhost.com';mail($toaddress,$subjects,$mailcontent,$fromaddress);
推荐学习:《php视频教程》
以上就是php email发送失败怎么办的详细内容。