自从安装lnmp环境后,lnmp下mail函数不能发送邮件的问题依然是出现的,在这里,我不建议大家使用sendmail作为发信,理由就是效率低,速度慢。

  yum remove sendmail

  然后就开始安装Postfix了,这相对与sendmail要效率高很多,发信速度快,占用内存低,可以说是目前服务器发信首选,当然也有很多大神会说smtp也不错,那也没错,但个人爱好,我就喜欢服务器发信的简单!

  安装 Postfix

  yum install postfix

  更改默认MTA为Postfix:

  /usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix

  完事儿,再次检查下是否将MTA改为Postfix了:

  alternatives --display mta

  配置Postfix,vi编辑main.cf

  vi /etc/postfix/main.cf

  打开后分别找到以下几项,将其前面的#去掉,并做配置:

  myhostname = mail.2zzt.com

  mydomain = 2zzt.com

  myorigin = $mydomain

  inet_interfaces = all

  mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

  mynetworks = 192.168.100.10/28, 127.0.0.0/8

  relay_domains =

  home_mailbox = Maildir/

  不喜欢vi在线编辑的,可以直接下载main.cf上传到服务器的/etc/postfix/main.cf进行替换吧

  检测并启动Postfix

  service postfix status

  //若未启动,执行以下命令:

  service postfix start

  设置开机启动

  chkconfig postfix on

  到这一步Postfix算是OK了,但我们还是得到php.in里配置下sendmail的绝对路径!

  使用命令打开编辑php.ini

  vi /usr/local/php/etc/php.ini

  输入?sendmail_path 查找定位(或者手动跳转找到sendmail_path),你会发现默认是下面的代码

  ;sendmail_path =

  按 i 进入编辑,将这行修改为

  sendmail_path = /usr/sbin/sendmail -t -i

  按 Esc 键退出编辑,输入 :wq 保存退出

  重启php-fpm进程

  /etc/init.d/php-fpm restart

  Linux lnmp下mail函数无法发送邮件的解决方法就介绍到这里了,因为sendmail效率低,比较浪费时间,这里推荐使用postfix发送邮件。