Created
April 7, 2017 10:34
-
-
Save thehungrycoder/73edac1566d2b2d73eebca8b1dd2ebd9 to your computer and use it in GitHub Desktop.
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 | |
namespace Examples\Transmissions; | |
require dirname(__FILE__).'/../bootstrap.php'; | |
use SparkPost\SparkPost; | |
use GuzzleHttp\Client; | |
use Http\Adapter\Guzzle6\Client as GuzzleAdapter; | |
$httpClient = new GuzzleAdapter(new Client()); | |
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]); | |
$promise = $sparky->transmissions->post([ | |
'content' => [ | |
'from' => [ | |
'name' => 'SparkPost Team', | |
'email' => '[email protected]', | |
], | |
'subject' => 'First Mailing From PHP', | |
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', | |
'text' => 'Congratulations, {{name}}! You just sent your very first mailing!', | |
], | |
'options' => [ | |
'open_tracking' => false, | |
'click_tracking' => false | |
], | |
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], | |
'recipients' => [ | |
[ | |
'address' => [ | |
'name' => 'YOUR_NAME', | |
'email' => 'YOUR_EMAIL', | |
], | |
], | |
], | |
]); | |
try { | |
$response = $promise->wait(); | |
echo $response->getStatusCode()."\n"; | |
print_r($response->getBody())."\n"; | |
} catch (\Exception $e) { | |
echo $e->getCode()."\n"; | |
echo $e->getMessage()."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment