3 回答
TA贡献1772条经验 获得超6个赞
要获得两者$_POST ,$_GET您可以使用$_REQUEST适用于两者的东西。
在您的代码中替换
$subject = $_GET['subject'];
和
$subject = $_REQUEST['subject'];
如果有人直接在浏览器中直接点击了网址,但没有设置主题,则可以阻止他们使用
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...");
}
TA贡献1943条经验 获得超7个赞
尝试一下。
<?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...");
?>
TA贡献1828条经验 获得超3个赞
如果您要从网址参数中提取值,则需要使用$_GET 全局变量来获取这样的数据,
<?php
$to_email = "person@gmail.com";
$subject = $_GET['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...");
}
?>
- 3 回答
- 0 关注
- 301 浏览
添加回答
举报