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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment
