0

我需要一些帮助,我正在为一个好朋友建立一个网站,我需要一些联系表格方面的帮助。我在网上找到了代码,但它不能正常工作。它发送电子邮件但并非所有表格都正确,并且不发送图片。此外,当我发送表单时,它应该链接到页面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>";
?>
4

3 回答 3

0

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

mail()使用首先将照片从服务器附加到PHP 电子邮件附件脚本来发送图像mail()

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

于 2012-07-11T05:05:17.420 回答
0

正如 Blender 指出的那样,代码非常不安全。恶意内容很容易被插入。mail.php 中也没有提到“照片”

$fileImage = $_POST['photo'];

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

于 2012-07-11T04:45:02.833 回答
0

您应该清理您的输入。在每个输入上使用mysql_real_escape_string或运行stripslashes$_POST.

 $user = mysql_real_escape_string($_POST['user']);
于 2012-07-11T04:52:34.213 回答