
Untitled
By: a guest on
Aug 21st, 2012 | syntax:
None | size: 1.08 KB | hits: 18 | expires: Never
<?php
$url = 'http://sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$fileName = 'myfile';
$filePath = dirname(__FILE__);
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example@sendgrid.com',
'subject' => 'test of file sends',
'html' => '<p> the HTML </p>',
'text' => 'the plain text',
'from' => 'example@sendgrid.com',
'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
);
print_r($params);
$request = $url.'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);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);