仅制作一个简单的提交表单,似乎无法正常工作。
它甚至不会报告错误,这很奇怪。
检查了php.ini,一切似乎也很好。
HTML:
<form id="submit-form" action="receiving.php" method="POST">
<h3>Submit a Link</h3>
<fieldset>
<table>
<tr>
<td><label for="name">You</label></td>
<td><input id="name" name="name" type="text" placeholder="Your Twitter or Blog ect." /></td>
</tr>
<tr>
<td><label for="submit-links">Link(s)</label></td>
<td><input id="sumbit-links" name="submit-links" type="text" placeholder="" required="" /></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="SUBMIT" /></td>
</tr>
</table>
</fieldset>
</form>
receive.php:
<?php
error_reporting(-1);
$name = $_POST['name'];
$submit-links = $_POST['submit-links'];
if(isset($_POST['submit'])){
$from_add = "[email protected]";
$to_add = "[email protected]";
$subject = "Your Subject Name";
$message = "Name:$name \n Sites: $submit-links";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion()
if(mail($to_add,$subject,$message,$headers)){
$msg = "Mail sent";
}
}
print "<p>Thanks $name</p>";
?>
任何帮助将非常感激 :)
您的表单存在一些问题,我在发布此答案之前对其进行了测试。
如Jeremy Miller
他的答案(+1
Jeremy btw)所指出的,在变量中使用连字符无效,请改用下划线。
您还缺少分号'X-Mailer: PHP/' . phpversion()
,顺便说一句,在此之后,您不应该使用(出于安全目的),但是...如果您绝对要使用它,'X-Mailer: PHP/' . phpversion();
请像下面这样添加它-咨询EDIT(建议用法)以下。
成功提交后,这$msg = "Mail sent";
不会显示消息“ Mail sent
”,因为您只将变量分配给了文本;您需要在echo it
下面添加的内容;这不是一个错误,但是如果您不打算使用它,为什么要拥有它。(眨眼)。
HTML表格
<form id="submit-form" action="receiving.php" method="POST">
<h3>Submit a Link</h3>
<fieldset>
<table>
<tr>
<td><label for="name">You</label></td>
<td><input id="name" name="name" type="text" placeholder="Your Twitter or Blog ect." /></td>
</tr>
<tr>
<td><label for="submit_links">Link(s)</label></td>
<td><input id="sumbit_links" name="submit_links" type="text" placeholder="" required="" /></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="SUBMIT" /></td>
</tr>
</table>
</fieldset>
</form>
的PHP
<?php
error_reporting(-1);
$name = $_POST['name'];
$submit_links = $_POST['submit_links'];
if(isset($_POST['submit']))
{
$from_add = "[email protected]";
$to_add = "[email protected]";
$subject = "Your Subject Name";
$message = "Name:$name \n Sites: $submit_links";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent";
echo $msg;
}
}
print "<p>Thanks $name</p>" ;
?>
我建议您使用以下PHP,因为如果直接访问PHP文件,则当前的条件语句将引发以下错误,这可能会发生。
另外,使用'X-Mailer: PHP/' . phpversion()
可以使人们知道您使用的是哪个PHP版本。
我拥有良好的权威,使用它是一个安全漏洞。他的名字现在使我不知所措,但是一旦我记得,我将添加它。
注意:未定义的索引:第4行上的...中的名称
注意:未定义的索引:第5行中...中的submit_links
我已经在if(isset($_POST['submit']))
条件语句中设置了变量。
<?php
error_reporting(-1);
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$submit_links = $_POST['submit_links'];
$from_add = "[email protected]";
$to_add = "[email protected]";
$subject = "Your Subject Name";
$message = "Name:$name \n Sites: $submit_links";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent";
echo $msg;
}
print "<p>Thanks $name</p>" ;
}
// else conditional statement for if(isset($_POST['submit']))
else {
echo "Sorry, you cannot do that from here. Please fill in the form first.";
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句