[英]Send mail from localhost with Sendgrid API - Php & Curl integration
我正在嘗試使用 Sendgrid API 集成和 PHP 和 Curl 從本地主機發送郵件。 當我運行下面的代碼時,什么也沒有發生(沒有電子郵件,也沒有錯誤/消息):
<?php
$email = "****@mail.com";
$name = "Miguel Martins";
$body = "Miguel is the king. <br><br><a href='https://google.com'>Google</a>";
$subject = "Teste Email";
$headers = array(
'Authorization: Bearer SG.gfgffgfgfdrgreeegv.lX-fgfgegehynte-frdvdyvryryhavaryuyyuyy',
'Content-Type: application/json'
);
$data = array(
"personalizations" => array(
array(
"to" => array(
array(
"email" => $email,
"name" => $name
)
)
)
),
"from" => array(
"email" => "****@mail.com"
),
"subject" => $subject,
"content" => array(
array(
"type" => "text/html",
"value" => $body
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLINFO_HEADER_OUT, true); // enable tracking
curl_setopt($ch, CURLOPT_URL, "https://api.sendgrid.com/v3/mail/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT); // request headers
curl_close($ch);
echo $response;
?>
我錯過了什么?
謝謝你的幫助。
解決方案:
終於找到這里的問題了。 Cacert.pem 丟失並且 mod_ssl 未在 Apache 的 httpd.conf 中啟用。 在此處找到解決方案: cURL 錯誤 60:SSL 證書:無法獲得本地頒發者證書
終於找到這里的問題了。 Cacert.pem 丟失並且 mod_ssl 未在 Apache 的 httpd.conf 中啟用。 在此處找到解決方案:cURL 錯誤 60:SSL 證書:無法獲得本地頒發者證書
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.