I need help sending jQuizzy results Via email

孤人 提交于 2020-01-05 12:27:24

问题


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 = "example@example.com";
$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.


回答1:


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.




回答2:


Try sending the data as an object.

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


来源:https://stackoverflow.com/questions/8364593/i-need-help-sending-jquizzy-results-via-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!