简体   繁体   English

我的联系表格不起作用

[英]My contact form will not work

I have a contact form that will not work I've been trying to get it to work for months trying different tutorials with no luck. 我有一个联系表格,该表格无法正常工作。我已经尝试了好几个月,尝试使用不同的教程却没有运气。

please take a look here 在这里看看

I followed this tutorial this time 这次我遵循了本教程

THIS IS THE CODE I HAV ON THE FROM THE FIRST LINK EXACTLY THE SAME! 这是我从第一个链接上获得的代码,完全相同! Contact Form 联系表

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

AND THE PHP: 和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";
}
?>

All I want is a simple contact form something like below: and the correct php to make it work. 我想要的只是一个简单的联系表单,如下所示:和正确的php使其起作用。 Thanks in advance 提前致谢

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

If the code you posted is ALL of your PHP code then the issue is that you're not capturing the $_POST data. 如果您发布的代码是所有PHP代码,则问题在于您没有捕获$_POST数据。

ie

$subject ="$subject";

Should be: 应该:

$subject = $_POST['subject'];

and so on... 等等...

ALSO

"$subject" is being treated as a string. "$subject"被视为字符串。 If $subject is set elsewhere use $subject 如果$subject设置在其他地方,请使用$subject

In addition to the first answer, from a brief scan, you're not executing the mail command either and turning it into a string: 除了第一个答案之外,通过简短的扫描,您也不会执行mail命令并将其转换为字符串:

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

To execute it: 要执行它:

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

You're not capturing the values of variables. 您没有捕获变量的值。 You need to use $_POST['nameAttribute'] to store the form inputs in PHP. 您需要使用$_POST['nameAttribute']将表单输入存储在PHP中。

$subject ="$subject";

This declaration will not do what you expect it to. 此声明将不会执行您期望的操作。 If you want to get the subject from the form, you'll have to add a new <input> field for that and then use the following to get the user input value: 如果要从表单中获取主题,则必须为此添加一个新的<input>字段,然后使用以下命令获取用户输入值:

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

Also, your code that handles sending of email is incorrect, too. 另外,您处理电子邮件发送的代码也不正确。 It is: 它是:

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

You don't need to wrap it in single quotes. 您无需将其用单引号引起来。 It should be: 它应该是:

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

So, finally after applying all the changes, it will look like this: 因此,最终在应用所有更改之后,它将如下所示:

<?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";
}   

}
?>

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM