使用PHP在Google App Engine上发送邮件时出错

问题描述 投票:0回答:1

我有Lumen在Google App Engine实例上运行,一切都很棒,除了发送邮件。无论我尝试什么,标准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: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\r\n" .
        'X-Mailer: Punkr/1.0';
    return mail($to_email, $subject, $body, $headers);
}

有什么建议?

google-app-engine lumen php-7.2
1个回答
0
投票

您的发送邮件不起作用可能是由于不同的原因:

  1. 发件人的电子邮件ID应作为所有者添加到AppEngine项目中,或使用服务帐户ID作为发件人。 Documentation
  2. 如果上述内容对您不起作用,您可以尝试其他方法。 use google\appengine\api\mail\Message; try { $message = new Message(); $message->setSender('[email protected]'); $message->addTo('[email protected]'); $message->setSubject('Example email'); $message->setTextBody('Hello, world!'); $message->send(); echo 'Mail Sent'; } catch (InvalidArgumentException $e) { echo 'There was an error'; }

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

© www.soinside.com 2019 - 2024. All rights reserved.