【发布时间】:2013-12-30 11:22:19
【问题描述】:
我一直在进一步处理网页上的联系表单,但无法使其正常运行。 (通过包含并在 apache2.2 本地服务器上运行)。
<?php
if($_SERVER['Request_Method'] != 'POST') {
$self = $_SERVER['PHP_SELF'];
?>
<form method="POST" action="<?php echo $self; ?>">
<table>
<tr>
<td style="width:100px;">
Name:
</td>
<td>
<input style="width:150px; height:25px;" placeholder="First Name" type="text" id="custname" name="custname">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input style="width:150px; height:25px;" placeholder="Last Name" type="text" id="cust2name" name="cust2name">
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input style="width:250px; height:25px;" placeholder="Example@domain.com" type="text" id="custemail" name="custemail">
</td>
</tr>
<tr>
<td>
Subject:
</td>
<td>
<input style="width:250px; height:25px;" placeholder="RE:Appointment & Contact" type="text" id="textsubject" name="textsubject">
</td>
</tr>
<tr>
<td>
Message:
</td>
<td>
<textarea id="custtext" name="custtext" placeholder="Please enter your message here..." rows="6" style="resize:none; font-family:arial; width:500px; height:75px;"cols="25"></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="Send"><input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
<?php
} else {
$name = $_POST['custname'];
$email = $_POST['custemail'];
$text = $_POST['custtext'];
$subject = $_POST['textsubject'];
$emailto = "reconnectsteam@hotmail.co.uk";
$header = "From: $name <$email>\r\nReply-To: $email\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type:text/html;charset=iso-8859-1\r\n";
$message = "From: $name, Email: $email<br /><hr />$text";
$mail($emailto, $subject, $message, $header);
echo"Your email has been sent, it will be proccessed within 48hours.";
}
?>
只是想知道这段代码在通过 apache 2.2 启动时是否可以工作(电子邮件不会发送,但其余代码是否仍然可以正常工作并运行?目前看来不是。有什么错误吗?(不包括数据库)。
谢谢,
录音
【问题讨论】:
-
你有什么错误吗?
-
注意电子邮件标头注入。
-
无法从您的本地计算机发送邮件。将它上传到服务器上,它就会工作。
-
在PHP中,数组键是区分大小写的,所以至少
$_SERVER['Request_Method']应该是$_SERVER['REQUEST_METHOD'] -
感谢心碎和 jedwards 的信息,很高兴知道。今天晚些时候将尝试上传。没有错误只是一个可疑的页面刷新,我将在以后添加安全协议。这只是为了测试目的。
标签: php html forms submit contact