【问题标题】:Error sending mails on Google App Engine with PHP使用 PHP 在 Google App Engine 上发送邮件时出错
【发布时间】:2019-03-02 09:06:14
【问题描述】:

我在 Google App Engine 实例上运行 Lumen,一切都很好,除了发送邮件。无论我尝试什么,标准的 PHP mail() 都会返回 false,但我在日志中找不到错误。

/**
 * Deliver an email
 * 
 * @param string $to_email
 * @param string $body
 * @param string $subject
 * 
 * @return bool
 */
static public function send($to_email, $body, $subject)
{
    $headers = 'From: myemail@gmail.com' . "\r\n" .
        'Reply-To: myemail+punkr@gmail.com' . "\r\n" .
        'X-Mailer: Punkr/1.0';
    return mail($to_email, $subject, $body, $headers);
}

有什么建议吗?

【问题讨论】:

  • 好吧,GAE好像找不到sendmail了。我尝试将 sendmail_path 设置为正常位置,但没有找到。有谁知道正确的位置吗?我之前没有发现这一点的原因是错误输出只是:“sh: 1: -t: not found”
  • 我最终改用了外部邮件程序 (SendGrid)。我怀疑这纯粹是 GAE 上的 PHP 7.2 问题。如果出现其他答案,我会回过头来,因为我宁愿不使用外部提供者。

标签: google-app-engine lumen php-7.2


【解决方案1】:

您的发送邮件无法正常工作可能是由于不同的原因:

  1. 发件人的电子邮件 ID 应添加为 AppEngine 项目中的所有者或使用服务帐户 ID 作为发件人。 Documentation
  2. 如果上述方法不适合您,您可以尝试其他方法。

     use google\appengine\api\mail\Message;
    
     try {
         $message = new Message();
         $message->setSender('from@example.com');
         $message->addTo('to@example.com');
         $message->setSubject('Example email');
         $message->setTextBody('Hello, world!');
         $message->send();
         echo 'Mail Sent';
         } catch (InvalidArgumentException $e) {
         echo 'There was an error';
        }
    

希望这能回答你的问题!!!!!!

【讨论】:

  • 感谢您的努力,但并没有太大帮助。问题是由于找不到 sendmail 二进制文件。而另一种方法最后也使用 PHPs mail() 并因此发送邮件。 ://
  • 你能显示你的错误 bcz use google\appengine\api\mail\Message; 这应该对你有用。
猜你喜欢
  • 2015-02-25
  • 2012-07-08
  • 1970-01-01
  • 2015-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-27
相关资源
最近更新 更多