PHP EMAIL使用POST方法时生成不起作用

时间:2017-04-01 07:44:55

标签: php

我已经创建了一个页面,它将接收3个变量,并根据发送到该页面的数据发送电子邮件。但是当我从表单发送数据时,在使用POST时我得到HTTP ERROR 500。 当使用GET方法和在URL中发送数据时,相同的代码正在工作。可能是什么错误?

<!doctype html>
<html>
<head>
<title>MAIL</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div>
<?php


 $emailTo=$_POST['to_address'];
 $subject=$_POST['subject'];
 $body="$_POST['body'];
 $headers="From: myemail@mysite.com";

 if (mail($emailTo, $subject, $body, $headers)) {

 echo "Mail sent successfully!";

 } else {

 echo "Mail not sent!";

 }


?>
</div>
</body>
</html>

3 个答案:

答案 0 :(得分:0)

500表示内部服务器错误。大多数情况下,源代码中存在错误。

切换

theano.scan

$body="$_POST['body'];

你真的应该逃避邮件功能的参数。看看这个答案:

escape mail fucntion

答案 1 :(得分:0)

你这里有拼写错误 - &gt; $ body =“$ _ POST ['body']; / *双引号未关闭* / 加:你应该检查POST数据并进行清理,因为它根本不是安全的

答案 2 :(得分:0)

您的代码中有拼写错误。 关闭此行中的双引号:

$body="$_POST['body'];