我正在尝试通过使用 JSON.stringify 编码然后在 PHP 中解码,然后通过电子邮件发送 JS 数组的内容。我收到成功警报,表明数据已发送到 PHP,但电子邮件未通过。任何人都可以发现任何明显我遗漏/错误的东西吗?
数组已通过.push函数填充,我可以在 HTML 中很好地输出,所以我知道它已填充。
使用 ajax 对我的数据字符串进行编码:
dataString = myArray; 
var jsonString = JSON.stringify(dataString);
 $.ajax({
    type: "POST",
    url: "script.php",
    data: {data : jsonString}, 
    cache: false,
    success: function(){
       alert("Success");
    }
});
然后在PHP中:
<?php
$data = json_decode(stripslashes($_POST['data']));
$to = "my@email.com";
$header = "Content-Type: text/html\r\nReply-To";
$subject = "This is my Subject Line";
$body = 
    @"
    <strong>The data is:</strong> $data
    ";
    if(mail($to, $subject, $body, $header)) {
        die("true");    
        } else {
            die("There was an error sending the email.");   
        }
?>
电子邮件根本没有通过,我根本没有收到任何错误消息。有人可以帮忙吗?谢谢!