I am trying to send mail from localhost using Sendgrid API integration, with PHP and Curl. When I run the code below nothing happens (no email and no error/ message):
<?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;
?>
What am I missing?
Thanks for your help.
SOLUTION:
Finally found what was the problem here. Cacert.pem was missing and mod_ssl wasn't enabled in Apache's httpd.conf . Found the solution here: cURL error 60: SSL certificate: unable to get local issuer certificate