search
Homephp教程php手册php中mail函数发送邮件失败的解决方法

这篇文章主要介绍了php中mail函数发送邮件失败的解决方法,涉及针对Linux运行平台相关组件的配置技巧,具有一定的参考借鉴价值,需要的朋友可以参考下

本文实例讲述了php中mail函数发送邮件失败的解决方法。分享给大家供大家参考。具体分析如下:

php中mail函数是一个自带的发邮件的函数,但是如果你真的要使用mail函数来发邮件那必须是要给你系统安装sendmail组件才可以,下面我就碰到mail发送不了邮件的问题,下面一起来看看解决办法吧.

之前的那台服务器转移过来后,发现网站用mail()发送邮件发不了,但是发现sendmail明明已经安装,如果没有安装sendmail可以执行,代码如下:

复制代码 代码如下:

yum install sendmail

对了,主机名要设置一个域名格式的,例如:jb51.net,不然重启sendmail的时候会特别久才启动起来,否则要等很久,代码如下:

复制代码 代码如下:

hostname jb51.net

接着看看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脚本测试代码,代码如下:

复制代码 代码如下:

$send = mail('yourEmail@lisizhang.com', '邮件标题', '测试邮件内容,如果收到此邮件,,表示mail函数成功启用!');
if($send){
echo 'true';
}else{
echo 'false';
}
?>


如果返回结果false说明邮件发送失败,如果返回true表示邮件发送成功.

希望本文所述对大家的php程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.