我使用HTML和PHP创建了一个联系表单。
现在,当用户提交联系表单时,他会使用回显消息重定向到新页面,而我希望此消息显示在一个小弹出窗口中。
HTML代码:
<form action="/assets/bootstrap/php/emailscript.php" method="post">
<input type="text" placeholder="Name" name="Name" oninvalid="setCustomValidity('Please enter your name')"
onchange="try{setCustomValidity('')}catch(e){}" required >
<input type="text" placeholder="Company" name="Company" oninvalid="setCustomValidity('Please enter your Company name')"
onchange="try{setCustomValidity('')}catch(e){}" required >
<input type="text" placeholder="Email" name="Email" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" oninvalid="setCustomValidity('Please enter a valid e-mail address')"
onchange="try{setCustomValidity('')}catch(e){}" >
<input type="text" placeholder="Subject" name="Subject" oninvalid="setCustomValidity('Please enter a Subject')"
onchange="try{setCustomValidity('')}catch(e){}" required >
<textarea rows="5" placeholder="Message" name="Message" oninvalid="setCustomValidity('Please Write your Message')"
onchange="try{setCustomValidity('')}catch(e){}" required ></textarea>
<button type="submit" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
</form>
</div>
</div>
</div>
PHP代码:
<?php
if(isset($_POST['Name']))
{
$name=$_POST['Name'] ;
$company=$_POST['Company'] ;
$from=$_POST['Email'] ;
$message=$_POST['Message'] ;
$to="contact@website.com" ;
$subject="Website contact form";
$headers .= 'From: '.$name.' | '.$company.' | '.$from.' ' . "\r\n";
mail ($to, $subject, $message, $headers ) ;
echo "Your Email has bean sent.";
}
?>
由于