Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $url = 'http://sendgrid.com/';
  3. $user = 'USERNAME';
  4. $pass = 'PASSWORD';
  5. $fileName = 'myfile';
  6. $filePath = dirname(__FILE__);
  7. $params = array(
  8.     'api_user'  => $user,
  9.     'api_key'   => $pass,
  10.     'to'        => 'example@sendgrid.com',
  11.     'subject'   => 'test of file sends',
  12.     'html'      => '<p> the HTML </p>',
  13.     'text'      => 'the plain text',
  14.     'from'      => 'example@sendgrid.com',
  15.     'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
  16.   );
  17. print_r($params);
  18. $request =  $url.'api/mail.send.json';
  19. // Generate curl request
  20. $session = curl_init($request);
  21. // Tell curl to use HTTP POST
  22. curl_setopt ($session, CURLOPT_POST, true);
  23. // Tell curl that this is the body of the POST
  24. curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
  25. // Tell curl not to return headers, but do return the response
  26. curl_setopt($session, CURLOPT_HEADER, false);
  27. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  28. // obtain response
  29. $response = curl_exec($session);
  30. curl_close($session);
  31. // print everything out
  32. print_r($response);