我是 PHP 新手,我无法弄清楚。下面您将看到我的 PHP 电子邮件表单。问题是,如果用户忘记输入电子邮件并且已经写了长消息然后点击提交。然后页面将重新加载,并出现一条短信并说:您忘记了您的电子邮件。但是现在整条消息已经从表格中删除了,他们必须重新写一遍。我如何在不重新加载页面/删除已输入信息的情况下回显他们忘记了电子邮件或消息。
<?php
function email() {
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
if ($email)
if ($message)
{
//send email
$to = "xxx@example.com";
$subject = "xxx" ;
$from = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: sent/');
exit();
}
else {
echo "You forgot your message.";
}
else {
echo "You forgot your email.";
}
}
?>
<form class="mail_form" accept-charset="ISO-8859-1" method='POST'>
<input class="input_mail" name='email' type='text' placeholder="Your email">
<textarea id="textarea_mail" accept-charset="ISO-8859-1" name='message' cols="30" rows="5" placeholder="Your message"></textarea>
<input class="send_mail" type='submit' name='submit'>
</form>
<?php if(isset($_POST['submit']))
{
echo email();
}
?>