我需要帮助通过电子邮件发送 jQuizzy 结果

发布于 2024-12-19 16:03:38 字数 1109 浏览 0 评论 0原文

我希望通过电子邮件发送 jQuery 测验“jQuizzy”的结果。

这是将 POST 发送到名为 send.php 的文件的代码

          if (config.sendResultsURL !== null) 
      {
          console.log("OH HAI");
          var collate =[];
          for (r=0;r<userAnswers.length;r++)
          {
              collate.push('{questionNumber:"'+parseInt(r+1)+'", UserAnswer:"'+userAnswers[r]+'"}');
          } 
          $.ajax({
                  type: 'POST',
                  url: "send.php",
                  data: '[' + collate.join(",") + ']',
                  complete: function () {console.log("OH HAI");}
                });
      }

,下面是发送电子邮件的简单 PHP 代码。

<?php
$to = "[email protected]";
$subject = "jQuizzy!";

$jsonStr = $_POST["ajax"];
$json = json_decode($jsonStr);

$body = "$json";

mail($to, $subject, $body);
?>

编辑:抱歉,问题是我的结果被发布到 send.php 页面,因为电子邮件正在处理,但电子邮件是普通/空的。

编辑2:我什至没有考虑检查php错误日志,我发现我的服务器没有任何设置,但是在设置它们之后,php方面似乎没有错误。

I am looking to send the results from the jQuery quiz "jQuizzy," via email.

This is the code that is sending the POST to file named send.php

          if (config.sendResultsURL !== null) 
      {
          console.log("OH HAI");
          var collate =[];
          for (r=0;r<userAnswers.length;r++)
          {
              collate.push('{questionNumber:"'+parseInt(r+1)+'", UserAnswer:"'+userAnswers[r]+'"}');
          } 
          $.ajax({
                  type: 'POST',
                  url: "send.php",
                  data: '[' + collate.join(",") + ']',
                  complete: function () {console.log("OH HAI");}
                });
      }

and here is the simple PHP code to send the email.

<?php
$to = "[email protected]";
$subject = "jQuizzy!";

$jsonStr = $_POST["ajax"];
$json = json_decode($jsonStr);

$body = "$json";

mail($to, $subject, $body);
?>

EDIT: Sorry the issue is that I the results are being posted to the send.php page because the email is going through, but the email is plain/empty.

EDIT 2: I didn't even think about checking the php-error logs to which I found out my server didn't have any set up, but after setting them up it seems there are no errors on the php side of things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北音执念 2024-12-26 16:03:38

data 参数应该是有效的 url 编码数据或对象哈希。您传递的是一个字符串,看起来可能是 JSON。这没有任何意义,但很难提出建议,因为你还没有真正说出你的问题是什么。

The data parameter supposed to be either valid url-encoded data or an object hash. What you passing is a string what looks like it might be JSON. That doesn't make any sense, but it is hard to suggest something since you haven't really said what your problem is.

苏佲洛 2024-12-26 16:03:38

尝试将数据作为对象发送。

data: {
    ajax: '[' + collate.join(",") + ']'
},

Try sending the data as an object.

data: {
    ajax: '[' + collate.join(",") + ']'
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文