我的联系表格不起作用

时间:2013-07-11 23:10:59

标签: php html html-form contact contact-form

我有一个不起作用的联系表单我一直试图让它工作几个月尝试不同的教程而没有运气。

take a look here

这次我跟着this tutorial

这是我从第一个链接完全相同的代码!               联系表单          

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
 <table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
 <td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
 </tr>
 <tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
 <td>&nbsp;</td>
 <td><input type="submit" name="Submit" value="Submit"> <input type="reset"     name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

和PHP:

<?php

// Contact subject
$subject ="$subject";

 // Details
$message="$detail";


// Mail of sender
$mail_from="$customer_mail";

// From
$header="from: $name <$mail_from>";


// Enter your email address
$to ='contact@kieshajewel.com';

$send_contact='mail($to,$subject,$message,$header)';


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>

我想要的只是一个简单的联系表格,如下所示:以及正确的PHP,使其工作。提前致谢

<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />

<label for="City">City:</label>
<input type="text" name="City" id="City" />

<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />

<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>

<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>

3 个答案:

答案 0 :(得分:3)

如果您发布的代码是您的所有PHP代码,那么问题是您没有捕获$_POST数据。

$subject ="$subject";

应该是:

$subject = $_POST['subject'];

依旧......

ALSO

"$subject"被视为字符串。如果在其他位置设置了$subject,请使用$subject

答案 1 :(得分:1)

除了第一个答案之外,从简短的扫描中,您还没有执行mail命令并将其转换为字符串:

$send_contact='mail($to,$subject,$message,$header)';

执行它:

mail($to,$subject,$message,$header);

答案 2 :(得分:1)

您没有捕获变量的值。您需要使用$_POST['nameAttribute']在PHP中存储表单输入。

$subject ="$subject";

此声明不符合您的预期。如果您想从表单中获取主题,则必须为其添加新的<input>字段,然后使用以下内容获取用户输入值:

$subject = $_POST['subject']; //assuming the name attribute was 'subject'

此外,处理电子邮件发送的代码也不正确。它是:

$send_contact='mail($to,$subject,$message,$header)';

您无需将其用单引号括起来。它应该是:

$send_contact = mail($to,$subject,$message,$header);

所以,最后在应用所有更改之后,它将如下所示:

<?php

if(isset($_POST['submit'])) { //checking if form was submitted
$subject = "Your subject"; //subject
$city = $_POST['City'];
$mail_from = $_POST['email'];
$message= $_POST['Message'];

// From
$header="from: $name <$mail_from>";
$to ='contact@kieshajewel.com';

$send_contact = mail($to,$subject,$message,$header); //sending email

if($send_contact)
{
echo "We've recived your contact information";
}
else
{
echo "ERROR";
}   

}
?>

希望这有帮助!