我正在尝试从我在GAE上部署但无法发送的PHP应用程序发送电子邮件。
我的PHP代码:
<?php
use google\appengine\api\mail\Message;
$name=$email=$query="";
if($_SERVER["REQUEST_METHOD"]=="POST"){
$name = $_POST["name"];
$email = $_POST["email"];
$query = $_POST["query"];
require_once 'google/appengine/api/mail/Message.php';
$mail_options = [
"sender" => $email,
"to" => "abc@gmail.com",
"subject" => "Subject",
"textBody" => $query,
];
try {
$message = new Message($mail_options);
$message->send();
} catch (InvalidArgumentException $e) {
echo "not send";
}?>
我的日志
INFO 2014-07-31 21:40:31,711 mail_stub.py:142] MailService.Send
From: bca@gmail.com
To: abc0@gmail.com
Subject: Subject
Body:
Content-type: text/plain
Data length: 3
INFO 2014-07-31 21:40:31,711 mail_stub.py:305] You are not currently sending out real email. If you have sendmail installed you can use it by using the server with --enable_sendmail.
但是here没有给出安装他们刚刚指示使用GAE API发送邮件的任何外部应用程序。
我该怎么办?
我的PHP代码有问题吗?
答案 0 :(得分:6)
您收到该错误是因为您在localhost上运行它,如果您将其部署到您的appengine云并将“发送自”设置为链接到该项目的管理员电子邮件,就像保罗所说的那样,它应该可以正常运行。当我用localhost测试它时,我得到了同样的错误,但是在部署时,它工作正常。