Created
July 31, 2013 10:00
-
-
Save sebmih/6120859 to your computer and use it in GitHub Desktop.
A working PHP script that uses a local file as an attachment via the Web API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $url = 'http://sendgrid.com/'; | |
| $user = '******'; | |
| $pass = '******'; | |
| $fileName = 'music.mp3'; | |
| $filePath = dirname(__FILE__); | |
| $params = array( | |
| 'api_user' => $user, | |
| 'api_key' => $pass, | |
| 'to' => '[email protected]', | |
| 'subject' => 'test of file sends', | |
| 'html' => '<p> the HTML </p>', | |
| 'text' => 'the plain text', | |
| 'from' => '[email protected]', | |
| '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); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment