我将以下代码另存为send.php:
<?php
$to_email = "person@gmail.com";
$subject = $_POST['subject'];
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me@myWebsite.com";
if ( mail($to_email, $subject, $body, $headers)) {
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
?>
如果我导航到https://myWebsite.com/Stuff/send.php
,电子邮件将发送
并制作$subject = "something"
但是如果我将$subject
设置为POST变量。当我在浏览器中写入此URL时,它不会发送主题(例如,电子邮件仍然发送,但主题现在为空):
https://myWebsite.com/Stuff/send.php?subject=notworking
我一直在为这个问题绞尽脑汁,并且已经挣扎了几个小时。有人知道吗?
答案 0 :(得分:0)
如果要从URL参数中提取值,则需要使用{
"id": "78a07cea-be2b-499c-b82b-e4f510260484",
"version": "1.0.0",
"actors": [
{
"id": "1234567",
"type": "XXX",
"role": "111"
},
{
"id": "7654321",
"type": "YYY",
"role": "222"
}
],
"payload": {
"name":"",
"number":""
}
}
全局变量来获取这样的数据,
$_GET
答案 1 :(得分:0)
要同时获得$_POST
和$_GET
,您可以使用$_REQUEST
,两者都适用。
在您的代码中替换
$subject = $_GET['subject'];
使用
$subject = $_REQUEST['subject'];
如果某人直接在浏览器中点击了没有参数主题的URL,则可以阻止他们使用
if(!empty($_REQUEST['subject']))
{
$to_email = "person@gmail.com";
$subject = $_REQUEST['subject'];
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me@myWebsite.com";
if ( mail($to_email, $subject, $body, $headers))
echo("Email successfully sent to $to_email...");
else
echo("Email sending failed...");
}
答案 2 :(得分:0)
尝试一下。
<?php
$to_email = "person@gmail.com";
$subject = (isset($_GET['subject']) && (!empty($_GET['subject']))?$_GET['subject']:"No Subject";
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me@myWebsite.com";
if ( mail($to_email, $subject, $body, $headers))
echo("Email successfully sent to $to_email...");
else
echo("Email sending failed...");
?>