|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Examples\Transmissions; |
| 4 | + |
| 5 | +require dirname(__FILE__).'/../bootstrap.php'; |
| 6 | + |
| 7 | +use SparkPost\SparkPost; |
| 8 | +use GuzzleHttp\Client; |
| 9 | +use Http\Adapter\Guzzle6\Client as GuzzleAdapter; |
| 10 | + |
| 11 | +$httpClient = new GuzzleAdapter(new Client()); |
| 12 | + |
| 13 | +/* |
| 14 | + * configure options in example-options.json |
| 15 | + */ |
| 16 | +$sparky = new SparkPost($httpClient, $options); |
| 17 | + |
| 18 | +$promise = $sparky->transmissions->post([ |
| 19 | + 'content' => [ |
| 20 | + 'from' => [ |
| 21 | + 'name' => 'SparkPost Team', |
| 22 | + 'email' => 'from@sparkpostbox.com', |
| 23 | + ], |
| 24 | + 'subject' => 'Mailing With Recipient List From PHP', |
| 25 | + 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email to everyone on your recipient list!</p></body></html>', |
| 26 | + 'text' => 'Congratulations, {{name}}! You just sent an email to everyone on your recipient list!', |
| 27 | + ], |
| 28 | + 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], |
| 29 | + 'recipients' => ['list_id' => 'RECIPIENT_LIST_ID'], |
| 30 | +]); |
| 31 | + |
| 32 | +try { |
| 33 | + $response = $promise->wait(); |
| 34 | + echo $response->getStatusCode()."\n"; |
| 35 | + print_r($response->getBody())."\n"; |
| 36 | +} catch (\Exception $e) { |
| 37 | + echo $e->getCode()."\n"; |
| 38 | + echo $e->getMessage()."\n"; |
| 39 | +} |
0 commit comments