我的联系表格上有HTML帮助吗?

时间:2012-07-11 03:56:02

标签: html forms contact-form

我需要一些帮助,我正在为一位好朋友建立一个网站,我需要一些关于联系表格的帮助。我在网上找到了代码,但它无法正常工作。它正确发送电子邮件但不是所有表格,并且不发送图片。此外,当我发送表单时,它应链接到contactus.html页面,但链接似乎也不起作用。任何人都可以帮助纠正这个代码,这将有很大帮助。非常感谢你。


以下是联系表单的HTML:

<div id="stylized" class="myform">
<form id="form" id="form" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Address
<span class="small">Add your home address</span>
</label>
<input type="text" name="address">
<label>Phone
<span class="small">Add a Phone Number</span>
</label>
<input type="text" name="phone">
<label>E-mail
<span class="small">Enter a valid E-mail</span>
</label>
<input type="text" name="email">
<label>Timeline
<span class="small">Range for your project</span>
</label>
<input type="text" name="timeline">
<label>Photo
<span class="small">Upload current picture</span>
</label>
<input type="file" name="photo">
<label>Description
<span class="small">Type Your Project Description</span>
</label>
<textarea name="message" rows="6" cols="25"></textarea>
<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>
</form>
</div>

这是mail.php,它应该有助于使表单正常工作。我想这就是问题所在:

<?php $name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$timeline = $_POST['timeline'];
$description = $_POST['description'];
$formcontent="From: $name \n Message: $message";
$recipient = "blanger@hawaii.edu";
$subject = "New Project Request from 2DadsDB.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contactus.html'>Go Back</a>";
?>

3 个答案:

答案 0 :(得分:0)

正如Blender所指出的那样,代码非常不安全。插入恶意内容很容易。 mail.php中也没有引用“photo”

$fileImage = $_POST['photo'];

您需要使用脚本上传和存储我相信的照片。最好看一下教程或完整的资源,而不是从头开始构建。

答案 1 :(得分:0)

您应该清理您的输入。在每个mysql_real_escape_string

上使用stripslashes$_POST.功能
 $user = mysql_real_escape_string($_POST['user']);

答案 2 :(得分:0)

mail()功能仅适用于发送消息。 要发送图像首先,您需要将照片上传到服务器To upload an image.

要使用mail()发送图片,请先将照片从服务器附加到mail() PHP e-mail attachment script

并使用$name = mysql_real_escape_string(strip_tags($_POST['name'])); 对于每个帖子,如姓名,电子邮件等,出于安全目的。

相关问题