简单的 PHP 邮件功能在 Amazon 服务器 EC2 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19559063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple PHP Mail function not working on Amazon server EC2
提问by kuldeep raj
Please see this code
请看这个代码
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
what is the problem in this code . Its not working on Amazon Linux server
这段代码有什么问题。它不适用于 Amazon Linux 服务器
Thanks
谢谢
回答by Sridhar
I'd had the same issue as you in sending an email using Php's mail()
. Installing send mail solved it for me.
我在使用 PHP 的mail()
. 安装发送邮件为我解决了它。
sudo apt-get install sendmail
回答by Avnish alok
I had the same issue with ec2 for php mail.
我对 ec2 的 php 邮件也有同样的问题。
Solution worked for me:
解决方案对我有用:
install sendmail by command:
sudo apt-get install sendmail
check the service whether its started or not by execuring follwing command
service sendmail status
Note: Output of above command should be something -
'Active: active (running)'
start the service if it is not running by following command
service sendmail start
After the service is started, send a test mail using following command:
echo "This is test mail body" | mail -s "Test Mail Subject" "[email protected]"
通过命令安装sendmail:
sudo apt-get install sendmail
通过执行以下命令检查服务是否已启动
service sendmail status
注意:上述命令的输出应该是 -
'Active: active (running)'
如果服务未运行,请通过以下命令启动服务
service sendmail start
服务启动后,使用以下命令发送测试邮件:
echo "This is test mail body" | mail -s "Test Mail Subject" "[email protected]"
Replace email with your email ID and see if you receive this email, if yes, then your mail setup is fine and now your php email should be working fine.
用您的电子邮件 ID 替换电子邮件并查看您是否收到此电子邮件,如果是,则您的邮件设置很好,现在您的 php 电子邮件应该可以正常工作。
If not, file to check for errors is /var/spool/mail/.
如果没有,检查错误的文件是 /var/spool/mail/。
回答by Harish Singh
Amazon server allow sendmail functionality using localhost. Please uncomment mail configuration in php.ini.
亚马逊服务器允许使用本地主机发送邮件功能。请在 php.ini 中取消对邮件配置的注释。
I have already done this and working fine.
我已经这样做了并且工作正常。
回答by StaleMartyr
are you willing to use other mailing framework? If yes, you can use phpmailer...it works fine for me.
您是否愿意使用其他邮件框架?如果是,您可以使用 phpmailer...它对我来说很好用。
here is the link on their site. http://phpmailer.worxware.com/
这是他们网站上的链接。http://phpmailer.worxware.com/
回答by mgPePe
Apparently sending PHP from EC2 is not possible until it gets unlocked by support. To unlock it visit: EC2 - Fresh PHP install - Mail not working
显然,在支持人员解锁之前,不可能从 EC2 发送 PHP。要解锁它,请访问: EC2 - Fresh PHP install - Mail not working
Otherwise, i will just quote @Charles answer:
否则,我只会引用@Charles 的回答:
This won't directly solve your issue (edit: I mean the error message you have now edited out), but Amazon EC2 instances have a really spotty mail reputation. You're probably going to have deliverability issues.
Thankfully Amazon created the Simple Email Service to go along with EC2, with a free level of service for EC2 customers. The API is pretty simple and there are transport adapters for many excellent PHP mailing libraries, like SwiftMailer (transport).
这不会直接解决您的问题(编辑:我的意思是您现在已删除的错误消息),但 Amazon EC2 实例的邮件声誉确实参差不齐。您可能会遇到可交付性问题。
幸运的是,Amazon 创建了 Simple Email Service 以配合 EC2,为 EC2 客户提供免费服务。API 非常简单,并且有许多优秀的 PHP 邮件库的传输适配器,例如 SwiftMailer(传输)。
So - no you can't send, but use Simple Email Service, libraries like SwiftMailer, or I would add services like SendGrid
所以 - 不,你不能发送,但使用Simple Email Service,像SwiftMailer这样的库,或者我会添加像SendGrid这样的服务
*Source: Another SO question on php mail & EC2
MEANWHILE:
I signed up for Simple Email Service, which is somewhat what SendGrid is doing. It's was very simple. First you request smtp user and password. You then either confirm an email for testing, or request production access [I didn't need that so I haven't gone through process]. And one caveat - use ssl://
in front of the host, or it will give you SMTP error: 530 5.7.0 Must issue a STARTTLS command first.
error. I was using CakePHP and EC2 when this happened.
MEANWHILE:我注册了 Simple Email Service,这在某种程度上是 SendGrid 正在做的。这很简单。首先您请求 smtp 用户和密码。然后,您可以确认一封用于测试的电子邮件,或者请求生产访问权限 [我不需要那个,所以我还没有完成流程]。还有一个警告 -ssl://
在主持人面前使用,否则会给您带来SMTP error: 530 5.7.0 Must issue a STARTTLS command first.
错误。发生这种情况时,我正在使用 CakePHP 和 EC2。
回答by DM007
Just follow instructions below (Tested for ubuntu 10x EC2)
只需按照以下说明(针对 ubuntu 10x EC2 测试)
sudo apt-get install php-pear // Install php-pear if not installed
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
sudo apt-get install postfix
sudo service apache2 restart
Enjoy!
享受!