脚本宝典收集整理的这篇文章主要介绍了php在同一页面中发送邮件并显示成功消息,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<form id="contact" action="contact.PHP" method="post"> <table class="contact" width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td >Your name:</td> <td ><input name="name" tyPE="text" id="name" size="32"></td> </tr> <tr> <td>Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td>Comment:</td> <td> <textarea name="comment" cols="45" rows="6" id="comment" ></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center;"> <input type="submIT" value="Submit" style="padding: 3px 22px;" /> </td> </tr> </table> </form>
if (isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $ToEmail = 'test@test.COM'; $EmailSubject = 'Site contact form '; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-to: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "Subject:".$_POST['subject']."<br />"; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail,$EmailSubject,$MESSAGE_BODY,$mailheader) or die ("Failure"); } ?>
现在这个工作正常.但是当用户点击提交按钮时,它只会重定向到contact.PHP文件.我希望当用户点击按钮时,它会以灯箱的形式在同一个html文件中显示成功消息,同时也会发送消息.有人能告诉我怎么做吗?任何帮助和建议都会非常明显.谢谢
更新
我有两个不同的文件.表单位于“contact.html”内,表单操作为“contact.PHP”,我想在“contact.html”页面中显示“成功”和“失败”消息,而不必转到“contact.PHP”.
<?PHP if (isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $ToEmail = 'test@test.com'; $EmailSubject = 'Site contact form '; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "Subject:".$_POST['subject']."<br />"; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; if(mail($ToEmail,$mailheader)) { echo "<script>alert('Mail was sent !');</script>"; echo "<script>document.location.href='contact.PHP'</script>"; } else { echo "<script>alert('Mail was not sent. Please try again later');</script>"; } }
以上是脚本宝典为你收集整理的php在同一页面中发送邮件并显示成功消息全部内容,希望文章能够帮你解决php在同一页面中发送邮件并显示成功消息所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。