Advertisement
Guest User

Untitled

a guest
Aug 13th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. $url = 'https://api.sendgrid.com/';
  2. $user = 'MY_USER_ID';
  3. $pass = 'MY_PASSWORD';
  4.  
  5. $fileName = 'week-19.pdf';
  6. $filePath = dirname(__FILE__);
  7.  
  8. $params = array(
  9. 'api_user' => $user,
  10. 'api_key' => $pass,
  11. 'to' =>'test@test.com',
  12. 'subject' => 'Sendgrid test of file sends',
  13. 'html' => '<p> the HTML </p>',
  14. 'text' => 'the plain text',
  15. 'from' => 'anna@test.com',
  16. 'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
  17. );
  18.  
  19. print_r($params);
  20.  
  21. $request = $url.'api/mail.send.json';
  22.  
  23. // Generate curl request
  24. $session = curl_init($request);
  25.  
  26. // Tell curl to use HTTP POST
  27. curl_setopt ($session, CURLOPT_POST, true);
  28.  
  29. // Tell curl that this is the body of the POST
  30. curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
  31.  
  32. // Tell curl not to return headers, but do return the response
  33. curl_setopt($session, CURLOPT_HEADER, false);
  34. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  35.  
  36. // obtain response
  37. $response = curl_exec($session);
  38. curl_close($session);
  39.  
  40. // print everything out
  41. print_r($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement