大家好我有这个联系表格
HTML
<form action="mail.php" method="POST">
<p>Team Name</p> <input type="text" name="name">
<p>Your Email</p> <input type="text" name="email">
<p>Players</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="radio" name="region" value="Europe" checked>Europe
<br>
<input type="radio" name="region" value="North America">North America
<br>
<input type="submit" value="Send">
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$region = $_POST['region'];
$message = $_POST['message'];
$formcontent=" From: $name $email $region $message";
$recipient = "myemail@email.com";
$subject = "$name";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
但是,当我点击提交时,它会自动重定向到新页面mail.php,如何让它保持在同一页面并用谢谢替换表单,或者如果不可能,请在下面的表单底部显示消息发送按钮。
最后一件事我想改变它,所以当它发送电子邮件本身时,数据采用这种格式,中间断开
Team Name
Email
Region
Players
与我在阅读我发送的电子邮件时所做的事情
From: My Team myemail@email.com Europe Player1
Player2
Player3
Player4
Player5
答案 0 :(得分:0)
快速回答:将表单操作更改为<?php echo $_SERVER['PHP_SELF']; ?>
。
但是,在执行此操作时,您需要检测表单是否已提交。您在教程和书籍等中看到的常见示例是检查是否已设置$_POST['submit']
(注意:您需要在提交中添加&#39; name&#39;属性{{上面的1}}标签使这项工作&gt ;;或验证页面是否已作为POST或GET请求的结果加载(示例如下Checking if form has been submitted - PHP提供):
<input>