我正在尝试从 curl 脚本编写 php 代码,但我认为我有一些问题
curl -X POST \
https://api.mailjet.com/v4/sms-send \
-H "Authorization: Bearer $MJ_TOKEN" \
-H 'content-type: application/json' \
-d '{
"From": "InfoSMS",
"To": "+33600000000",
"Text": "Hello World!"
}'
我的代码
$token = 'XXXXXXXXXXXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v4/sms-send');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'From' => 'InfoSMS',
'To' => '+33600000000',
'Text' => 'Hello World!'
));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Authorization: Bearer " . $token;
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_error($ch)) {
echo 'Error:' . curl_error($ch);
}
var_dump($result);
curl_close ($ch);
这是我第一次使用 curl 所以我真的不知道从哪里开始
萧十郎