Php echo json_encode响应不适用于邮件功能
我已使用Php echo json_encode响应不适用于邮件功能,php,json,curl,Php,Json,Curl,我已使用curl生成报告并向用户发送邮件 这是我的密码 $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, count($post)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); $ret
curl
生成报告并向用户发送邮件
这是我的密码
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($post));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$ret = curl_exec($ch);
$ret = json_decode($ret, true);
curl_close($ch);
print_r($ret);
在这里,我使用邮件函数返回json encode响应,但响应中没有get。
如果我评论send\u report\u to\u user
函数,那么我就能够得到响应
$to="test@gmail.com";
$name="Test";
$report_links='MYREPORT LINKS';
send_report_to_user($to,$name,$report_links);
echo json_encode(array('status'=>'success','message'=>"Report has been generated successfully. Please check your mail to view reports."));
die;
function send_report_to_user($to,$name,$report_links)
{
$mailheaders .= "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mailheaders .= "From: Mcs <do_not_reply@mcs.com>";
$subject = "Your Report is Ready";
$body_message='<p>Your Report is now ready to be viewed here:</p>
<p><a href="'.$report_links.'" target="_blank">Click Here to view report</a></p>
<p> </p>';
mail($to,$subject,$body_message,$mailheaders);
return true;
}
$to=”test@gmail.com";
$name=“测试”;
$report_links='MYREPORT links';
将报告发送给用户($to、$name、$report\u链接);
echo json_encode(数组('status'=>'success','message'=>“报告已成功生成。请检查您的邮件以查看报告”);
死亡
函数send_report_to_user($to、$name、$report_链接)
{
$mailheaders.=“MIME版本:1.0\r\n”;
$mailheaders.=“内容类型:text/html;charset=ISO-8859-1\r\n”;
$mailheaders.=“发件人:Mcs”;
$subject=“您的报告已准备就绪”;
$body_message='您的报告现在可以在此处查看:
';
邮件($to、$subject、$body\u message、$mailheaders);
返回true;
}
我认为您的向用户发送报告功能有问题。您正在使用变量$mailheaders
,但尚未定义它。在使用变量之前,请尝试定义它,它可能适合您
请尝试以下代码
function send_report_to_user($to,$name,$report_links)
{
$mailheaders = '';
$mailheaders .= "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mailheaders .= "From: Mcs <do_not_reply@mcs.com>";
$subject = "Your Report is Ready";
$body_message='<p>Your Report is now ready to be viewed here:</p>
<p><a href="'.$report_links.'" target="_blank">Click Here to view report</a></p>
<p> </p>';
mail($to,$subject,$body_message,$mailheaders);
return true;
}
函数发送报告给用户($to、$name、$report\u链接)
{
$mailheaders='';
$mailheaders.=“MIME版本:1.0\r\n”;
$mailheaders.=“内容类型:text/html;charset=ISO-8859-1\r\n”;
$mailheaders.=“发件人:Mcs”;
$subject=“您的报告已准备就绪”;
$body_message='您的报告现在可以在此处查看:
';
邮件($to、$subject、$body\u message、$mailheaders);
返回true;
}
您收到任何错误或异常吗?@RAUSHANKUMAR没有代码正常工作,只有未收到响应。邮件也已收到检查您在这里收到的邮件($to、$subject、$body\u message、$mailheaders)代码>@hassan,但函数调用位于die@RAUSHANKUMAR邮件工作正常