2016-05-13 13 views
0

私はAzureでホストされているサイトから電子メールをユーザーに送信するためにPHPスクリプトを作成しています。 SendGridを使用しています。Microsoftでsendgrid PHPを使用するAzure

$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アカウントをセットアップしています。提供されたユーザー名と私のパスワードが使用されています。誰かが私に間違っていることを教えてもらえますか?

+0

こんにちは、更新はありますか? –

答えて

0

デフォルトでは、AzureはAzure Web Appsの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で証明書を追加できます。

関連する問題