问题描述
我正在尝试使用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,CURLOPT_RETURNTRANSFER,1);
$response = curl_exec($ch);
$headerSent = curl_getinfo($ch,CURLINFO_HEADER_OUT); // request headers
curl_close($ch);
echo $response;
?>
我想念什么?
感谢您的帮助。
解决方案:
最后找到了这里的问题。 Cacert.pem丢失并且Apache的httpd.conf中未启用mod_ssl。在此处找到解决方案:cURL error 60: SSL certificate: unable to get local issuer certificate
解决方法
最后找到了这里的问题。 Cacert.pem丢失并且Apache的httpd.conf中未启用mod_ssl。在此处找到解决方案:cURL错误60:SSL证书:无法获取本地颁发者证书