如何更改 PHP 电子邮件表单(返回部分)以匹配 Javascript 和 html 模板?

最近我发布了一个问题PHP Script not send emails并阅读了很多类似的主题,比如AJAX JQUERY HTML EMAIL主题,但没有一个解决了我的问题。

我的问题是,当电子邮件成功发送时(我检查它),部分HTML没有运行,整个页面被刷新而不是作为主模板:(我想当发送回HTML时我无法为PHP发送响应)。我的目标只是将 PHP 文件更改为有效。

在主模板中,电子邮件的结果(发送或失败)完美完成如下,但在我的版本中存在如下问题:

http://img4.mukewang.com/60e7af3e000113d512000278.jpg

HTML:

<div class="alert alert-success hidden animated fadeIn" id="contactSuccess">

   <strong>Success!</strong> Your message has been sent to us.

</div>


<div class="alert alert-danger hidden animated shake" id="contactError">

   <strong>Error!</strong> There was an error sending your message.

</div>

JavaScript:

jQuery(document).ready(function(e) {

    "use strict";

    e("#contact-form").validate({

        submitHandler: function(s) {

            var o = e(s),

                a = e("#contactSuccess"),

                t = e("#contactError"),

                r = e(this.submitButton);

            r.button("loading"), e.ajax({

                type: "POST",

                url: o.attr("action"),

                data: {

                    name: o.find("#name").val(),

                    email: o.find("#email").val(),

                    subject: o.find("#subject").val(),

                    message: o.find("#message").val()

                },



HUH函数
浏览 133回答 1
1回答

德玛西亚99

为什么你只是在 php 端输出 url 然后在 javascript 端你调用你想要的脚本:PHP端$mail_status = mail($mail_to, $subject, $body_message, $headers);if ($mail_status) {&nbsp; &nbsp; echo "{'url':'contact_page.html#contactSuccess'}";} else {&nbsp; &nbsp; echo "{'url':'contact_page.html#contactError'}";}Javascript端complete: function(){&nbsp; &nbsp;...&nbsp; &nbsp;window.location = s.responseJSON.url&nbsp; &nbsp;...}
打开App,查看更多内容
随时随地看视频慕课网APP