我对$ pass和$ api_key感到困惑 它们是否相同,因为首先$ pass被分配了SendGrid用户名的密码,但是api_key被分配了$ pass。 如果它们相同,我们将使用我们在SendGrid上生成的api_key? 请帮助!!!
<?php
$url = 'http://sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
?>
答案 0 :(得分:0)
您尝试做的事情存在一些问题:
sendgrid.com
发送API调用,只能发送api.sendgrid.com
看起来你有一个非常古老的示例脚本用于测试。你从哪里得到的?