简单的PHP提交表单不起作用

前端之家收集整理的这篇文章主要介绍了简单的PHP提交表单不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
只是制作一个简单的提交表单,似乎无法使其正常工作.

它甚至不会报告奇怪的错误.

检查了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>

receiving.PHP

<?PHP 
error_reporting(-1);
$name = $_POST['name']; 
$submit-links = $_POST['submit-links']; 
if(isset($_POST['submit'])){
 $from_add = "submit@webdesignrepo.com"; 
 $to_add = "ben@webdesignrepo.com"; 
 $subject = "Your Subject Name";

 $message = "Name:$name \n Sites: $submit-links";

 $headers = 'From: submit@webdesignrepo.com' . "\r\n" .
'Reply-To: ben@webdesignrepo.com' . "\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 =“邮件发送”;成功提交后不会打印“邮件已发送”消息,因为您只是将变量分配给文本;你需要回应我在下面添加内容;这不是一个错误,但如果你不打算使用它,为什么要这样做. (眨眼).

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 = "submit@webdesignrepo.com"; 
$to_add = "ben@webdesignrepo.com"; 
$subject = "Your Subject Name";
$message = "Name:$name \n Sites: $submit_links";

$headers = 'From: submit@webdesignrepo.com' . "\r\n" .
'Reply-To: ben@webdesignrepo.com' . "\r\n" .
'X-Mailer: PHP/' . PHPversion();

if(mail($to_add,$headers)) 
{
    $msg = "Mail sent";

echo $msg;

} 
}

print "<p>Thanks $name</p>" ;

?>

编辑(暗示用法)

我建议你使用下面的PHP,因为你现在的条件语句会抛出以下错误,如果直接访问PHP文件,可能会发生.

另外,使用’X-Mailer:PHP /’. PHPversion()让人们知道你正在使用哪个PHP版本.

我有很好的权威,使用它是一个安全漏洞.他的名字现在逃脱了我,但是一旦我记得,我会加上它.

Notice: Undefined index: name in… on line 4

Notice: Undefined index: submit_links in… on line 5

我已经在if(isset($_ POST [‘submit’]))条件语句中设置了变量.

<?PHP 
error_reporting(-1);

if(isset($_POST['submit']))
{
$name = $_POST['name']; 
$submit_links = $_POST['submit_links']; 
$from_add = "submit@webdesignrepo.com"; 
$to_add = "ben@webdesignrepo.com"; 
$subject = "Your Subject Name";
$message = "Name:$name \n Sites: $submit_links";

$headers = 'From: submit@webdesignrepo.com' . "\r\n" .

'Reply-To: ben@webdesignrepo.com' . "\r\n";

if(mail($to_add,$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.";
}

?>
原文链接:https://www.f2er.com/php/130609.html

猜你在找的PHP相关文章