我试图创建一个包含邮件功能的调查页面。但是,当我尝试代码时,它不发送任何内容,没有错误只是一个空白页面。 我是一般的编码新手,所以可能是我的代码中的一些重大错误,对不起。 我在谷歌上尝试了很多选项,但没有成功。
我的代码:
$to = "my-email@mail.com";
$subject = "Survey";
$name = "MyName";
$from = "my-2nd-email@mail.com";
$quest1 = $_POST['quest1'];
$quest2 = $_POST['quest2'];
$quest3 = $_POST['quest3'];
$message = $quest1 . " " . $quest2 . " " . $quest3;
if (mail ($to, $subject, $message")){
echo "
<h2>Your message is sent!</h2>
<b>To:</b> $to
<b>Subject: Survey</b>
<b>Svar:</b>
$quest1'<BR>
$quest2<BR>
$quest3<BR>";
}
else{
echo "Error: Message not sent";
}
?>
和HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Kontakt</title>
</head>
<body>
<h2>Survey</h2>
<form name="kontakt" method="post" action="formmail.php">
<p><br>
Question1?<br>
<input name="quest1" type="text" value="" size="60">
</p>
<p>Question2?<br>
<input name="quest2" type="text" value="" size="60">
</p>
<p>Question3?<br>
<textarea name="quest3" cols="60" rows="2"></textarea>
</p>
<p><br>
<br>
<input name="submit" type="submit"
value="Send message">
</p>
</form>
</body>
</html>
答案 0 :(得分:3)
你需要修改这一行:
if (mail ($to, $subject, $message"))
到这个
if (mail ($to, $subject, $message))
"
$message
字符
您还需要在回声中添加"
。
所以它应该是这样的:
if (mail($to, $subject, $message)) {
echo "<h2>Your message is sent!</h2>
<b>To:</b> $to
<b>Subject: Survey</b>
<b>Svar:</b>
$quest1<BR>
$quest2<BR>
$quest3<BR>";
} else {
echo "Error: Message not sent";
}
答案 1 :(得分:0)
试试这个..
$to = "my-email@mail.com";
$subject = "Survey";
$name = "MyName";
$from = "my-2nd-email@mail.com";
$quest1 = $_POST['quest1'];
$quest2 = $_POST['quest2'];
$quest3 = $_POST['quest3'];
$message = $quest1 . " " . $quest2 . " " . $quest3;
$headers = "From:$from\r\n";
if(mail($to, $subject, $message,$headers)){
echo "<h2>Your message is sent!</h2>
<b>To:</b> $to
<b>Subject: Survey</b>
<b>Svar:</b>
$quest1'<BR>
$quest2<BR>
$quest3<BR>";
}
else
echo "Error: Message not sent";
答案 2 :(得分:0)
在"
之后删除邮件功能中的$message
并在此echo
中创建正确的字符串
if (mail($to, $subject, $message))
{
echo '<h2>Your message is sent!</h2>
<b>To:</b> $to
<b>Subject:Survey</b>
<b>Svar:</b>
$quest1."<br>"
$quest2."<br>"
$quest3."<br>"';
}
else
{
echo "Error: Message not sent";
}