2016-05-13 76 views
0

我正在開發一個PHP腳本,用於從Azure上承載的站點向用戶發送電子郵件。我正在使用SendGrid,使用以下代碼:在Microsoft Azure上使用sendgrid PHP

$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上添加證書。