在配置了lnmp环境后,出现了mail函数不能发送邮件的问题,其实有两种方法,一是使用sendmail组件,而是使用postfix。

方法一,使用sendmail组件来发邮件 
  1.安装 sendmail 组件 
  yum install sendmail 
  2.使用下面的命令重启php-fpm进程 
  /etc/init.d/php-fpm restart 
  3.检测sendmail是否运行正常 
  /etc/init.d/sendmail status 
  如果显示正在运行running 就可以。 
  可能用到的命令 
  /etc/init.d/sendmail start (启动sendmail) 
  /etc/init.d/sendmail stop (关闭sendmail) 
  /etc/init.d/sendmail restart (重启sendmail) 
  4.配置php.ini,填写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 保存退出 
  5.重启php-fpm进程 
  /etc/init.d/php-fpm restart 
  这样就成功了,如果不放心,新建一个php文件,命名为 mail.php ,可以使用下面代码测试下。 
  《?php 
  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发送邮件

相关文章:

  • 2021-05-15
  • 2022-02-22
  • 2021-10-22
  • 2021-08-28
  • 2021-07-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案