【发布时间】:2018-07-29 15:39:49
【问题描述】:
我关注了this doc,这是我的代码:
$url = "https://mail.zoho.com/api/accounts/662704xxx/messages";
$param = [ "fromAddress"=> "myemail@mydomain.com",
"toAddress"=> "somewhere@gmail.com",
"ccAddress"=> "",
"bccAddress"=> "",
"subject"=> "Email - Always and Forever",
"content"=> "Email can never be dead ..."];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
die;
响应是:
{"data":{"errorCode":"INVALID_TICKET","moreInfo":"Invalid ticket"},"status":{"code":400,"description":"Invalid Input"}}
而响应的意思是:(根据this)
BAD REQUEST - 请求 API 中传递的输入无效或不正确。请求者必须更改输入参数并再次发送请求。
知道如何解决吗?
【问题讨论】:
-
使用 PHPMailer 发送邮件。
-
@Devrajverma 我的服务器上没有安装 SMTP 服务器。
-
也许删除
ccAddress和bccAddress如果它们为空,看看你是否能获得成功。看起来其他一切都很好,但我觉得 zoho 正在打破,因为这两个输入为空因此,无效 -
您可能需要添加一个
Content-Type: application/json标头,告诉接收器您实际上是在请求正文中发送JSON ...通过将字符串传递给CURLOPT_POSTFIELDS,默认为application/x-www-form-urlencoded -
@CBroe 我添加了
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));,但遗憾的是结果还是一样。