close

 

SendGrid 的 Web API 與 REST API 十分類似,但並非真的是 REST 型 API,因為在大部分的呼叫中,GET 和 POST 動詞可以交換使用。

 $url = 'https://api.sendgrid.com/';

 $user = 'USERNAME';
 $pass = 'PASSWORD';

 $params = array(
      'api_user' => $user,
      'api_key' => $pass,
      'to' => 'john@contoso.com',
      'subject' => 'testing from curl',
      'html' => 'testing body',
      'text' => 'testing body',
      'from' => 'anna@contoso.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);

 

參考來源:https://docs.microsoft.com/zh-tw/azure/store-sendgrid-php-how-to-send-email

 

arrow
arrow

    Austin 發表在 痞客邦 留言(0) 人氣()