【发布时间】:2012-01-22 21:09:17
【问题描述】:
我在 PHP 方面完全是 n00b(可以说是一般的 Web 开发:/),但我查看了大量示例,比较了我的代码,但我只是想不通出来。基本上所有发生的事情都是contact.php文件刚刚下载到我的电脑上。啊。此外,这个客户没有要求任何字段验证,这就是为什么那里没有。救命!!
这是我的html-
<form action="contact.php" method="post">
<fieldset>
<legend><strong>Get A Quote!</strong>
</legend>
Call me at 555-555-5555, or email me at <a href="">email@emaiul.com</a>, or use the form below.<br /><br />
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Name" name="name" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Email" name="email" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Phone" name="phone" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<textarea style="width:370px; height:55px; font-size:14px;" name="message" size="50" type="text">Message</textarea>
</div>
</div><!-- /clearfix -->
</fieldset>
<button type="submit" name="saveForm" style="background-image: url(static/img/btn-submit.png); width:150px; height:37px;"></button>
</form>
和php-
<?php
if(isset($_POST['saveForm'])) {
$to = "steven@urethrafranklin.org";
$subject = "Inquiry from website";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
} else {
echo "Sorry, something went wrong. Please email me at user@user.com.";
}
?>
【问题讨论】:
-
您是否 100% 将 php 安装在运行它的服务器上?顺便说一句:您至少应该在基本级别上进行验证,否则您的脚本很容易受到其他人使用它来发送垃圾邮件(通过注入邮件标头)的攻击。
-
你是使用FastCGI还是其他方法来执行PHP?执行 PHP 内容的服务器配置是什么样的?
-
顺便说一句,我希望你的配置中打开了
suhosin.mail.protect,否则这太容易被人滥用了。 -
我不知道为什么它会这样做,除了提到的只是一个注释,我可能是错的,但是
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";应该有 $ 变量的转义,例如:$body = "From: {$name_field}\n E-Mail: {$email_field}\n Message:\n {$message}";。我可能是错的,但这是我被教导的方式。