从本地表单发布到 App Engine 托管的 PHP 脚本
Posting from local form to App Engine hosted PHP script
我正在尝试按照本教程进行操作:https://html.form.guide/email-form/php-form-to-email/ 将简单的 php 脚本部署到 google App Engine。我想将表单从本地主机和 post 加载到应用程序引擎 link。当我这样做时,$_POST
是空的。当 post 从另一个 server/localhost 连接到应用引擎托管服务时,这是一个问题吗?
代码:
app.yaml:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: .*
script: formemailer.php
php 脚本:
<?php
if(!isset($_POST['submit']))
{
echo "error; you need to submit the form!";
}
?>
表格:
<form method="post" action="https://<url>.appspot.com/formemailer.php">
<p>
<label for='name'>Enter Name: </label><br>
<input type="text" name="name">
</p>
<input type="submit" name="submit" value="submit" />
</form>
您可以通过写入真实的 url 将数据 post 发送到另一台服务器,如果您的 url 没问题,则必须传递 post 数据,但是如果您检查了 url 这是真的,但你仍然有问题,你可以使用 api 调用来做到这一点
header('Content-Type: application/json');
$data = json_decode(file_get_contents("php://input"));
header("Content-Type: application/json");
$name = $data->name;
$to = "yourmail@mail.com";
$message = $name . "hiii";
$subject = "test mail";
mail($to, $message, $subject);
通过这样做,您可以使用 curl 调用 api 来执行邮件功能,并通过 curl 请求从服务器传递信息,我希望您能找到这个回答有帮助,如果 mail()
功能不适合你或给你一个错误,你可以试试 phpmailer 如果你有任何问题,你可以发表评论,我会回答他们
appspot.com主机受到了很多钓鱼攻击。它可能因安全问题而被屏蔽。
Is this an issue when posting from another server/localhost to an app-engine hosted service?
不,服务器在发送时收到 POST 请求。
是的,因为你这样做有问题。
应该可以,但现在该怎么办?
使用浏览器中的网络工具验证实际发送到服务器的内容。这可能已经为您提供了更多见解。
现在浏览器自带网络工具,请看:
- Chrome(或 Chromium、Vivaldi 等):Inspect network activity
- 火狐:Network Monitor
或浏览器的文档。
对于 Google App Engine 上的 PHP 5 应用程序 运行,您可以在以下位置找到处理表单输入的专门教程:
但是强烈 推荐(不仅在 App Engine 上,而且在一般情况下)使用 PHP 7 运行时。这个 应该 独立于你的问题,但是最好从 PHP 7 开始(如果你允许我发表评论)。
此处提供了一般信息(也适用于 PHP 5 和 7):
如果您想了解 PHP 通常如何独立于任何平台处理此问题,您可以在此处的 PHP 手册中找到概述:
对于浏览器中您所要求的一般处理 - 一个主机上的表单(甚至 HTML 本地文件)发布到另一台主机,请参阅此相关 Q/A:
- Cross Domain Form POSTing
我正在尝试按照本教程进行操作:https://html.form.guide/email-form/php-form-to-email/ 将简单的 php 脚本部署到 google App Engine。我想将表单从本地主机和 post 加载到应用程序引擎 link。当我这样做时,$_POST
是空的。当 post 从另一个 server/localhost 连接到应用引擎托管服务时,这是一个问题吗?
代码:
app.yaml:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: .*
script: formemailer.php
php 脚本:
<?php
if(!isset($_POST['submit']))
{
echo "error; you need to submit the form!";
}
?>
表格:
<form method="post" action="https://<url>.appspot.com/formemailer.php">
<p>
<label for='name'>Enter Name: </label><br>
<input type="text" name="name">
</p>
<input type="submit" name="submit" value="submit" />
</form>
您可以通过写入真实的 url 将数据 post 发送到另一台服务器,如果您的 url 没问题,则必须传递 post 数据,但是如果您检查了 url 这是真的,但你仍然有问题,你可以使用 api 调用来做到这一点
header('Content-Type: application/json');
$data = json_decode(file_get_contents("php://input"));
header("Content-Type: application/json");
$name = $data->name;
$to = "yourmail@mail.com";
$message = $name . "hiii";
$subject = "test mail";
mail($to, $message, $subject);
通过这样做,您可以使用 curl 调用 api 来执行邮件功能,并通过 curl 请求从服务器传递信息,我希望您能找到这个回答有帮助,如果 mail()
功能不适合你或给你一个错误,你可以试试 phpmailer 如果你有任何问题,你可以发表评论,我会回答他们
appspot.com主机受到了很多钓鱼攻击。它可能因安全问题而被屏蔽。
Is this an issue when posting from another server/localhost to an app-engine hosted service?
不,服务器在发送时收到 POST 请求。
是的,因为你这样做有问题。
应该可以,但现在该怎么办?
使用浏览器中的网络工具验证实际发送到服务器的内容。这可能已经为您提供了更多见解。
现在浏览器自带网络工具,请看:
- Chrome(或 Chromium、Vivaldi 等):Inspect network activity
- 火狐:Network Monitor
或浏览器的文档。
对于 Google App Engine 上的 PHP 5 应用程序 运行,您可以在以下位置找到处理表单输入的专门教程:
但是强烈 推荐(不仅在 App Engine 上,而且在一般情况下)使用 PHP 7 运行时。这个 应该 独立于你的问题,但是最好从 PHP 7 开始(如果你允许我发表评论)。
此处提供了一般信息(也适用于 PHP 5 和 7):
如果您想了解 PHP 通常如何独立于任何平台处理此问题,您可以在此处的 PHP 手册中找到概述:
对于浏览器中您所要求的一般处理 - 一个主机上的表单(甚至 HTML 本地文件)发布到另一台主机,请参阅此相关 Q/A:
- Cross Domain Form POSTing