Created
July 19, 2013 07:56
-
-
Save sebmih/6037471 to your computer and use it in GitHub Desktop.
A script that adds a new newsletter into a user's dashboard.
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 = '*****'; | |
| $identity = 'address1'; | |
| $params = array( | |
| 'api_user' => $user, | |
| 'api_key' => $pass, | |
| 'identity' => $identity, | |
| 'name' => 'NLAPI_test3', | |
| 'subject' => 'Hello NLAPI', | |
| 'text' => "Lord Jesus it's a fire!", | |
| 'html' => "<i>Lord Jesus it's a fire </i>" | |
| ); | |
| $request = $url.'api/newsletter/add.json'; | |
| $session = curl_init($request); | |
| curl_setopt ($session, CURLOPT_POST, true); | |
| curl_setopt ($session, CURLOPT_POSTFIELDS, $params); | |
| curl_setopt($session, CURLOPT_HEADER, false); | |
| curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
| $response = curl_exec($session); | |
| //Gather info about the time it took to make the request. | |
| if(!curl_errno($session)) | |
| { | |
| $info = curl_getinfo($session); | |
| echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; | |
| } | |
| echo "\n"; | |
| curl_close($session); | |
| //Decode the response from SendGrid and display it. | |
| $decoded_file = json_decode($response, true); | |
| foreach ($decoded_file as $k => $v) { | |
| echo "Response: ". $v ."!"; | |
| } | |
| echo "\n"; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment