仅制作一个简单的提交表单,似乎无法正常工作。

它甚至不会报告错误,这很奇怪。

检查了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 = "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();-咨询编辑 (建议用法)如下。
成功提交后,此$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 = "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";

echo $msg;

}
}

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

?>

编辑(建议用法)
我建议您使用以下PHP,因为如果直接访问PHP文件,则当前的条件语句将引发以下错误,这可能会发生。
另外,使用'X-Mailer: PHP/' . phpversion()可以使人们知道您使用的是哪个PHP版本。
我有很好的权限,使用它是一个安全漏洞。他的名字现在使我不知所措,但是一旦我记得,我将添加它。

我已经在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,$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.";
}

?>

10-04 21:26
查看更多