我正在尝试创建一个“联系我们”页面,但是一旦按下“发送”按钮,就会得到一个没有任何内容的空“空”邮件。该电子邮件中没有“来自”,“消息”或“主题”,我找不到问题。
以下是我的代码,contact.php:
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>
<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> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
send_contact.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 ='someone@somewhere.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";
}
?>
答案 0 :(得分:0)
您好尝试更改send_contact.php的第一行
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
为:
// Contact subject
$subject = $_POST['subject'];
// Details
$message= $_POST['details'];
但我建议您试试这个:http://teachingyou.net/php/simple-php-contact-form-using-ajax/
答案 1 :(得分:0)
也许你想要这样的东西
$subject =$_POST['subject'];
// Details
$message=$_POST['$detail'];
// Mail of sender
$mail_from=$_POST['customer_mail'];
答案 2 :(得分:0)
您在send_contact.php文件中错误地定义了变量。
$subject ="$subject";
应该是
$subject = $_POST['subject'];
与您的其他变种一起。 看一下表单教程和POST / GET / REQUEST,以便更好地了解正在发生的事情。