-1

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

请看这里

这次我跟着这个教程

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

<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>
4

3 回答 3

3

If the code you posted is ALL of your PHP code then the issue is that you're not capturing the $_POST data.

i.e.

$subject ="$subject";

Should be:

$subject = $_POST['subject'];

and so on...

ALSO

"$subject" is being treated as a string. If $subject is set elsewhere use $subject

于 2013-07-11T23:25:37.900 回答
1

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

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

要执行它:

mail($to,$subject,$message,$header);
于 2013-07-11T23:28:20.043 回答
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";
}   

}
?>

希望这可以帮助!

于 2013-07-11T23:34:30.273 回答