【问题标题】:Using sendgrid PHP on microsoft Azure在 Microsoft Azure 上使用 sendgrid PHP
【发布时间】: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 帐户,并且正在使用提供的用户名和我自己的密码。谁能告诉我,我做错了什么?

【问题讨论】:

    标签: php azure curl sendgrid


    【解决方案1】:

    默认情况下,Azure 不会为 Azure Web 应用生成 SSL 对等证书。如果在测试代码中添加代码$error = curl_error($session);,就会得到错误SSL certificate problem: self signed certificate in certificate chain

    您只需添加代码curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0); 即可绕过验证。

    否则,您可以关注Verify Peer Certificate from PHP cURL for Azure Apps 在 Azure Web Apps 上添加证书。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多