【发布时间】:2016-05-13 10:56:32
【问题描述】:
我正在编写一个 PHP 脚本,以便从托管在 Azure 上的站点向用户发送电子邮件。我正在使用 SendGrid,代码如下:
$url = 'https://api.sendgrid.com/';
$user = 'username';
$pass = 'password';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $email,
'subject' => "Bid Submission",
'html' => "",
'text' => "y",
'from' => $emailFrom,
);
$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);
但是上面的代码没有运行,也没有发送电子邮件。我已经设置了 SendGrid 帐户,并且正在使用提供的用户名和我自己的密码。谁能告诉我,我做错了什么?
【问题讨论】: