使用 Sendgrid API - Php 和 Curl 集成从本地主机发送邮件
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 中启用。在这里找到解决方案:
终于找到问题所在了。 Cacert.pem 丢失并且 mod_ssl 未在 Apache 的 httpd.conf 中启用。在此处找到解决方案:cURL 错误 60:SSL 证书:无法获取本地颁发者证书
我正在尝试使用 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 中启用。在这里找到解决方案:
终于找到问题所在了。 Cacert.pem 丢失并且 mod_ssl 未在 Apache 的 httpd.conf 中启用。在此处找到解决方案:cURL 错误 60:SSL 证书:无法获取本地颁发者证书