小舞一直用的是军哥的lnmp环境后,lnmp下mail函数不能发送邮件的问题依然是出现的,在这里,我不建议大家使用sendmail作为发信,理由就是效率低,速度慢,所以,一上来就得把他卸载了,这里我就直接说教程了,不墨迹!

  1. yum remove sendmail

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

  1. yum install postfix

更改默认MTA为Postfix:

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

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

  1. alternatives --display mta

配置Postfix,vi编辑main.cf

  1. vi /etc/postfix/main.cf

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

  1. myhostname = mail.5v13.com
  2. mydomain = 5v13.com
  3. myorigin = $mydomain
  4. inet_interfaces = all
  5. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  6. mynetworks = 192.168.100.10/28, 127.0.0.0/8
  7. relay_domains =
  8. home_mailbox = Maildir/

在这里我会给出main.cf的完整文件,省的大伙改错的,大家只需将main.cf文件里的5v13.com替换为你们自己的域名即可OK了
不喜欢vi在线编辑的,可以直接下载main.cf上传到服务器的/etc/postfix/main.cf进行替换吧
检测并启动Postfix

  1. service postfix status

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

  1. service postfix start

设置开机启动

  1. chkconfig postfix on

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

使用命令打开编辑php.ini

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

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

  1. ;sendmail_path =

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

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

按 Esc 键退出编辑,输入 :wq 保存退出
重启php-fpm进程

  1. /etc/init.d/php-fpm restart

[scbutton link="http://pan.baidu.com/s/1ntG9vS1" target="blank" variation="red"]main.cf下载地址[/scbutton]

发表回复

后才能评论