|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * For a more detailed explanation of how cc/bcc work with SparkPost, please |
| 5 | + * check out this article: https://support.sparkpost.com/customer/portal/articles/1948014 |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Examples\Transmisson; |
| 9 | + |
| 10 | +require_once dirname(__FILE__).'/../bootstrap.php'; |
| 11 | + |
| 12 | +//pull in API key config |
| 13 | +$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json'); |
| 14 | +$config = json_decode($configFile, true); |
| 15 | + |
| 16 | +use SparkPost\SparkPost; |
| 17 | +use GuzzleHttp\Client; |
| 18 | +use Ivory\HttpAdapter\Guzzle6HttpAdapter; |
| 19 | + |
| 20 | +$httpAdapter = new Guzzle6HttpAdapter(new Client()); |
| 21 | +$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]); |
| 22 | + |
| 23 | +try { |
| 24 | + $results = $sparky->transmission->send([ |
| 25 | + 'from' => [ |
| 26 | + 'name' => 'From Envelope', |
| 27 | + |
| 28 | + ], |
| 29 | + 'html' => '<p>An example email using cc with SparkPost to the {{recipient_type}} recipient.</p>', |
| 30 | + 'text' => 'An example email using cc with SparkPost to the {{recipient_type}} recipient.', |
| 31 | + 'subject' => 'Example email using cc', |
| 32 | + 'recipients' => [ |
| 33 | + [ |
| 34 | + 'address' => [ |
| 35 | + 'name' => 'Original Recipient', |
| 36 | + |
| 37 | + ], |
| 38 | + 'substitution_data' => [ |
| 39 | + 'recipient_type' => 'Original' |
| 40 | + ] |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'address' => [ |
| 44 | + 'name' => 'Carbon Copy Recipient', |
| 45 | + |
| 46 | + 'header_to' => '"Original Recipient" <[email protected]>', |
| 47 | + ], |
| 48 | + 'substitution_data' => [ |
| 49 | + 'recipient_type' => 'CC' |
| 50 | + ] |
| 51 | + ], |
| 52 | + ], |
| 53 | + 'customHeaders' => [ |
| 54 | + 'CC' => '"Carbon Copy Recipient" <[email protected]>' |
| 55 | + ] |
| 56 | + ]); |
| 57 | + echo 'Congrats! You sent an email with cc using SparkPost!'; |
| 58 | +} catch (\Exception $exception) { |
| 59 | + echo $exception->getAPIMessage()."\n"; |
| 60 | + echo $exception->getAPICode()."\n"; |
| 61 | + echo $exception->getAPIDescription()."\n"; |
| 62 | +} |
0 commit comments