我對我的表單有個疑問。提交表單後,您將被導向到一個頁面,然後是我放入的文本。問題是我希望此文本與表單所在的頁面(名爲contact.html)顯示在同一頁面上我使用兩個文件,其中一個是Mail_handler.php,另一個是contact.html。我已經嘗試過多種方法來修復它,但出於某種原因,我沒有成功。我希望你們能幫助我!您可以在下面找到HTML和PHP。如何在同一頁面上顯示消息?
<form method="POST" action="mail_handler.php">
<div class="col-sm-7 slideanim">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Naam" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="phone" name="phone" placeholder="Telefoonnummer" type="text" required>
</div>
<div class="col-sm-12 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="msg" name="msg" placeholder="Bericht" rows="5"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='[email protected]'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Bedankt voor uw bericht!"." ".$name.", Wij nemen zo snel mogelijk contact met u op.</h1>";
}
else{
echo "Something went wrong!";
}
}
>
你需要使用'ajax'通話,並通過其提交的。只要您喜歡,就可以在表單上顯示回覆。 – Panther