Sid*_*qui 4 php laravel guzzle
我正在尝试使用 ZohoMail 的 API 通过我的应用程序发送电子邮件。但它不断给我:
"{errorCode":"INVALID_METHOD"},"status":{"code":404,"description":"无效输入"}}
这是我尝试拨打的电话的链接:https : //www.zoho.com/mail/help/api/post-send-an-email.html#Request_Body
这是我的功能:
public static function sendEmail ($AccountId, $AuthCode, $FromAddress, $ToAddress, $Subject, $Content){
$client = new Client(); //GuzzleHttp\Client
$URI = 'http://mail.zoho.com/api/accounts/' . $AccountId . '/messages';
$headers = ['Content-Type' => 'application/json', 'Authorization' => 'Zoho-authtoken ' . $AuthCode];
$body = array('fromAddress' => $FromAddress, 'toAddress' => $ToAddress, 'subject' => $Subject, 'content' => $Content);
$Nbody = json_encode($body);
$response = $client->post($URI, $headers, $Nbody);
echo "DONE!";
}
Run Code Online (Sandbox Code Playgroud)
我试过改变我打电话的方式,但似乎这不是问题所在。我已经在 PostMan 中测试了通话,它工作正常,所以我拨打电话的方式可能有问题。任何帮助将非常感激。
您需要在同一个数组中创建数据和标题并作为第二个参数传递。像这样使用。
$client = new Client();
$URI = 'http://mail.zoho.com/api/accounts/'.$AccountId.'/messages';
$params['headers'] = ['Content-Type' => 'application/json', 'Authorization' => 'Zoho-authtoken ' . $AuthCode];
$params['form_params'] = array('fromAddress' => $FromAddress, 'toAddress' => $ToAddress, 'subject' => $Subject, 'content' => $Content);
$response = $client->post($URI, $params);
echo "DONE!";
Run Code Online (Sandbox Code Playgroud)
祝你好运!
| 归档时间: |
|
| 查看次数: |
26267 次 |
| 最近记录: |