2013-10-13 50 views
1

我配置我的Amazon EC2实例与使用下列URL的sendmail发送邮件: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sendmail.html 结束后,我加入了php.ini中的以下行:无法发送邮件EC2-PHP和sendmail

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

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

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

须藤/ usr/sbin目录/ sendmail的[email protected] [email protected]

但是当我试图从代码中运行它,它不工作

<?php 
    $to = "[email protected]"; 
    $subject = "Test mail"; 
    $message = "Hello! This is a simple email message."; 
    $from ="[email protected]"; 
    $headers = "From:" . $from; 
    $result = mail($to,$subject,$message,$headers); 

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

结果总是如此,日志中没有任何东西。 有人可以帮助,我在这里做错了什么?

+0

您是否想发送消息到'gmail.com.com'? – datasage

+0

对不起,我编辑的问题,来源不包括.com.com –

+0

结果返回true或false?你在/ var/log/maillog中看到与消息有关的任何东西吗?如果问题与发送或交付有关,则需要缩小范围。由于亚马逊IP位于垃圾邮件列表中,因此直接从EC2发送的邮件通常会被收件人过滤。 – datasage

回答

1

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

+0

感谢它可能没有解决我的问题,但我用sendgrid,它现在与web API –