我已经使用HTML和PHP创建了联系表单。此外,邮件正确地发送到邮件ID。但成功后的消息,它是重定向到form.php
页面可以有人请帮助我。这是我第一次尝试建立一个网站。如何在提交联系表单后在同一页面中获取成功消息?
这里是我的联系表格代码:
<form method="post" action="form.php">
<input name="name" required="required" placeholder="Your Name">
<input name="email" type="email" required="required" placeholder="Your Email">
<div class="clearfix"> </div>
<textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<div class="submit">
<input id="submit" name="submit" type="submit" value="Submit">
</div>
</form>
这里是我的form.php
:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: agriindiaexp.com';
$to = '[email protected]';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
$success = "Message successfully sent";
} else {
$success = "Message Sending Failed, try again";
}
}
?>
请帮助我。
检查:[http://stackoverflow.com/questions/5826784/how-do-i-make-a-php-form-that-submits-to-self](http://stackoverflow。 com/questions/5826784/how-do-i-make-a-php-form-that-submits-to-self) – Rohit
如果你想不刷新页面,请检查[http://www.codingcage.com/2015 /06/submit-php-form-without-page-refresh-jquery-ajax.html](http://www.codingcage.com/2015/06/submit-php-form-without-page-refresh-jquery- ajax.html) – Rohit
或'