PHP 函数 mail() 在 AWS EC2 服务器上不起作用 [英] PHP function mail() doesn't work on AWS EC2 server

查看:52
本文介绍了PHP 函数 mail() 在 AWS EC2 服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我安装了一个基于 Ubuntu 14.04 的 AWS EC2 虚拟服务器.但我有下一个问题:PHP 函数 mail() 不起作用.

Recently I installed an AWS EC2 virtual server based on Ubuntu 14.04. But I have the next problem: the PHP function mail() doesn't work.

  1. 我删除了 sendmail.
  2. 我安装了 sendmail:

  1. I removed sendmail.
  2. I installed sendmail:

sudo apt-get install sendmail

我检查它的工作:

ps -aux |grep sendmail

我更改了 php.ini:

I changed php.ini:

sendmail_path =/usr/sbin/sendmail

我跑:

sudo sendmailconfig

为所有类别选择.

  1. 重新启动服务:

  1. Restarted the service:

服务 sendmail 重启

将我的主机名添加到/etc/hosts:

Added my hostname to /etc/hosts:

127.0.0.1 localhost.localdomain localhost myhostname

我尝试测试发送:

echo -e "To: myemail@example.com\nSubject: Test\nTest\n" |sendmail -bm -t -v

所有电子邮件都存储在/var/mail/ubuntu 中.

我还需要做些什么吗?

推荐答案

Ubuntu 16.04 LTS(截至 2016 年 9 月用于 Amazon EC2 的默认"Ubuntu 映像)将需要为 PHP 安装和配置 Postfix MTA 以发送邮件.

Ubuntu 16.04 LTS, the "default" Ubuntu image for Amazon EC2 as of September 2016, will need the Postfix MTA installed and configured for PHP to send mail.

sudo apt-get update
sudo apt install mailutils

选择internet site"并输入正确的主机名.

Keep "internet site" selected and enter your proper host name.

然后使用您最喜欢的编辑器,vim 或 nano 或其他任何东西,并修复 main.cf 文件以仅处理来自本地网络接口(环回)的流量并将域设置为您正确的主机域名.

Then use your favorite editor, vim or nano or whatever, and fix up the main.cf file to process traffic from local network interfaces (loopback) only and to set the domain to your proper host domain name.

sudo systemctl restart postfix

查看详情:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04

这就是在运行 WordPress 应用程序的 Ubuntu 16.04 上运行出站电子邮件所需的全部魔法.

That is all the magic needed to get outbound email working on my Ubuntu 16.04 running a WordPress app.

祝你好运.

这篇关于PHP 函数 mail() 在 AWS EC2 服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆