【问题标题】:Failed sending mail EC2-PHP with SendMail使用 SendMail 发送邮件 EC2-PHP 失败
【发布时间】:2013-10-21 03:22:09
【问题描述】:

我将我的亚马逊 EC2 实例配置为使用带有以下 URL 的 sendmail 发送邮件: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sendmail.html 完成后,我在 php.ini 中添加了以下行:

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

我已经研究过其他解决方案,但它们没有帮助。 how to find out if PHP and sendmail are working together?

当我尝试从控制台发送电子邮件时,它会到达目的地。

sudo /usr/sbin/sendmail -f x@y.com x@gmail.com

但是当我尝试从代码运行它时它不起作用

<?php
    $to = "X@y.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from ="w@z.com";
    $headers = "From:" . $from;
    $result = mail($to,$subject,$message,$headers);

    if ($result)
    {
        echo "mail sent";
    }
    else
    {
        echo "error";
    }
?>

结果总是正确的,日志上没有任何内容。 有人可以帮忙吗,我在这里做错了什么?

【问题讨论】:

  • 您是否要向gmail.com.com 发送消息?
  • 对不起,我编辑了问题,来源不包括 .com.com
  • 结果返回真还是假?您在 /var/log/maillog 中看到与该消息相关的任何内容吗?如果问题与发送或交付有关,则需要缩小范围。由于亚马逊 IP 位于垃圾邮件列表中,直接从 EC2 发送的邮件通常会被收件人过滤。
  • 结果总是正确的,日志上什么也没有。

标签: php email amazon-web-services amazon-s3 amazon-ec2


【解决方案1】:

如果您的结果总是“真”,那么您的电子邮件可能会被 Spamhaus 阻止。因此,最好的方法是从 ec2 实例发送电子邮件是将中继电子邮件设置到不同的邮件服务器。您可以使用 sendgrid 每天免费发送 200 封电子邮件。否则,您可以使用 smtp 身份验证发送电子邮件。 Here is an example using gmail smtp server.

【讨论】:

  • 感谢它可能没有解决我的问题,但我使用了 sendgrid,它现在正在使用 web API
猜你喜欢
  • 1970-01-01
  • 2014-12-10
  • 2011-09-27
  • 1970-01-01
  • 1970-01-01
  • 2018-11-14
  • 2017-05-19
  • 2020-08-24
  • 1970-01-01
相关资源
最近更新 更多