PHP表单在提交后消失

时间:2015-03-25 05:32:03

标签: php

我正试着看看如何让页面确认它已被填写。

这就是我所拥有的。

<?php
if(!isset($_POST['submit']))
{echo
        '<form action="" method="post">
            <input type="text" placeholder="From" name="from"><br>
            <input type="text" placeholder="Subject" name="sub"><br>
            <input type="text" placeholder="Message"name="mess"><br>
            <input type="submit">
        </form>';}
else{
$to = 'test@test.com, '. $from=$_POST['from'];
$subject = $_POST['sub'];
$message = $_POST['mess'];

mail ( $to , $subject , $message);
    echo 'thanks for submitting!<br>';}

?>

1 个答案:

答案 0 :(得分:0)

替换以下代码:

mail ( $to , $subject , $message);
    echo 'thanks for submitting!<br>';

由此:

if(@mail($to, $subject, $message)) {
  echo "thanks for submitting";
}else{
  echo "Unable to submit your email.";
}

了解更多信息:http://php.net/manual/en/function.mail.php
祝你好运!