php中mail函数发送文件失败解决办法
php中mail函数是一个自带的发邮件的函数,但是如果你真的要使用mail函数来发邮件那必须是要给你系统安装sendmail组件才可以,下面我就碰到mail发送不了邮件的问题,下面一起来看看解决办法吧.
之前的那台服务器转移过来后,发现网站用mail()发送邮件发不了,但是发现sendmail明明已经安装,如果没有安装sendmail可以执行,代码如下:
yum install sendmail
对了,主机名要设置一个域名格式的,例如:phprm.com,不然重启sendmail的时候会特别久才启动起来,否则要等很久,代码如下:
hostname phprm.com
接着看看sendmail是否正常运行,代码如下:
service sendmail status
如果没有运行可以启动,status换成start,紧接着,编辑php.ini,可以在web环境下创建一个phpinfo,因为我用的是lnmp.
vi /usr/local/php/etc/php.ini
再查找:;sendmail_path =,按i编辑,替换为:
sendmail_path = /usr/sbin/sendmail -t -i
我的系统默认的是:sendmail_path = /usr/sbin/sendmail -t -i -f
这个-f 看来是让mail函数停用了,去掉-f后mail函数工作恢复正常,紧接着,重启PHP进程,一般是:service php restart LNMP是:service php-fpm restart,Apache下可以:service httpd restart
给大家分享个php脚本测试代码,代码如下:
<?php $send = mail('yourEmail@lisizhang.com', '邮件标题', '测试邮件内容,如果收到此邮件,表示mail函数成功启用!'); if($send){ echo 'true'; }else{ echo 'false'; }
如果返回结果false说明邮件发送失败,如果返回true表示邮件发送成功.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
