我对PHP还是很陌生,但是我已经设法通过网页前端的联系表来使用电子邮件系统。我遇到的问题是,一旦发送电子邮件,我想隐藏表格并显示一条消息,“谢谢您的电子邮件”。
我试图寻找解决方案,但是我唯一能找到的答案就是使用以下代码:header(“ Location:sentmail.html”);然后从此处将其重定向到另一个HTML页面,该页面与删除表单的联系人页面相同。我认为这是一种不好的做法,因为要在整个网站上使用多少联系表格,需要使用很多重复页面。
一旦发送了电子邮件,是否有一种方法可以显示“谢谢您的消息”,而不是重定向到sendmail.html页面。
感谢您抽出宝贵的时间阅读。
`<?php
extract($_POST);
if(isset($_POST['submit']))
$name = $_POST['first_name'];
$email = $_POST['email_address'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "jamie@sharpsdigital.co.uk";
$headers = "From: MLS systems Contact Form ";
$txt = "$name has sent you an email from the address. " .$email. "\n\n With the message of.\n\n" .$message. " \n\n This is an automated response from the contact form, Please click on the blue email address above to respond." ;
mail ($mailTo, $subject, $txt, $headers);
header("Location: sentmail.html");
?>`
这是PHP代码,在表单代码下方
<section class="free-appoinment-area">
<div class="container">
<form action="sendmail.php" method="post" class="free-appoinment-form">
<div class="row">
<div class="col-md-12">
<div class="sec-title text-left">
<h1>Any queries</h1><span class="decor"></span>
</div>
<div class="row">
<div class="col-md-12">
<div class="input-field">
<input name="first_name" placeholder="Your Name*" type="text">
<div class="icon-holder">
<span class="flaticon-people"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<input name="subject" placeholder="Your Subject" type="text">
<div class="icon-holder">
<span class="flaticon-people"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<input name="email_address" placeholder="Email Address*" type="text">
<div class="icon-holder">
<span class="flaticon-note"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-field">
<textarea name="message" placeholder="Your Message..."></textarea>
<div class="icon-holder comment">
<span class="flaticon-social-1"></span>
</div>
</div>
</div>
<div class="col-md-12">
<button type="submit" data-type="submit" name="submit" value="submit">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
答案 0 :(得分:0)
有数百种可能性,但简单地说,您可以获取mail()
的返回值并根据以下内容显示内容:
$success = mail('...');
if($success) {
echo 'Thank you!';
} else {
// output form here
}
当然,您也可以在表单处理程序中简单地将标志设置为true,但这在这里无法解释。
答案 1 :(得分:-1)
您可以使用php和css来实现。
php方法是使用 if else 语句,例如波纹管
if(isset($_POST['submit'])){
$name = $_POST['first_name'];
$email = $_POST['email_address'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "jamie@sharpsdigital.co.uk";
$headers = "From: MLS systems Contact Form ";
$txt = "$name has sent you an email from the address. " .$email. "\n\n With the message of.\n\n" .$message. " \n\n This is an automated response from the contact form, Please click on the blue email address above to respond." ;
if(mail ($mailTo, $subject, $txt, $headers)){
echo "Thanks for your contact.";
}
}else{ ?>
your form goes here
<?php }?>