Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function new_sendmail($to, $subject,$body,$from){
  2. try {
  3. $url = 'https://api.sendgrid.com/';
  4. $user = 'ACCOUNT_USERNAME';
  5. $pass = 'ACCOUNT_PASSWORD';
  6. $json_string = array('to' => array($to ));
  7.  
  8. $params = array('api_user' => $user,'api_key' => $pass,'x-smtpapi' => json_encode($json_string),'to' => $to,'subject' => $subject,'html' => $body,'text' => $body,'from' => $from);
  9. $request = $url.'api/mail.send.json';
  10. $session = curl_init($request);
  11. curl_setopt ($session, CURLOPT_POST, true);
  12. curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
  13. curl_setopt($session, CURLOPT_HEADER, false);
  14. curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  15. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  16. $response = curl_exec($session);
  17. curl_close($session);
  18. } catch (Exception $e) {
  19. echo 'Caught exception: ', $e->getMessage(), "\n";
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement