为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
HUH函数 2021-07-02 10:01:29
最近我发布了一个问题PHP Script not send emails并阅读了很多类似的主题,比如AJAX JQUERY HTML EMAIL主题,但没有一个解决了我的问题。我的问题是,当电子邮件成功发送时(我检查它),部分HTML没有运行,整个页面被刷新而不是作为主模板:(我想当发送回HTML时我无法为PHP发送响应)。我的目标只是将 PHP 文件更改为有效。在主模板中,电子邮件的结果(发送或失败)完美完成如下,但在我的版本中存在如下问题: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()                },
查看完整描述

1 回答

?
德玛西亚99

TA贡献1770条经验 获得超3个赞

为什么你只是在 php 端输出 url 然后在 javascript 端你调用你想要的脚本:


PHP端


$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) {

    echo "{'url':'contact_page.html#contactSuccess'}";

} else {

    echo "{'url':'contact_page.html#contactError'}";

}

Javascript端


complete: function(){

   ...

   window.location = s.responseJSON.url

   ...

}


查看完整回答
反对 回复 2021-07-09
  • 1 回答
  • 0 关注
  • 132 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信