// Send GRid with APi key
sendemails($to ,$subject,$html,$text);
function sendemails($to ,$subject,$html,$text) {
$pass ='apikey';
$params = array(
'to' => $to,
'subject' => $subject,
'html' => $html,
'text' => $text,
'from' => '',
);
$headr = array();
// set authorization header
$headr[] = 'Authorization: Bearer '.$pass;
$request = 'https://api.sendgrid.com/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);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_HTTPHEADER,$headr);
// obtain response
$response = curl_exec($session);
curl_close($session);
return json_decode($response,true);
}
// Send GRid with username APi key
function sendemails($to , $subject,$html,$text) {
$params = array(
'api_user' => self::$user,
'api_key' => self::$pass,
'to' => $to,
'subject' => $subject,
'html' => $html,
'text' => $text,
'from' => 'admin@viablitz.com',
);
$request = 'https://api.sendgrid.com/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);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
return json_decode($response,true);
}
0 comments:
Post a Comment
Don't Forget to comment