summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Leland <rich@richleland.com>2016-05-13 13:19:33 -0400
committerRichard Leland <rich@richleland.com>2016-05-13 13:19:33 -0400
commit6a3715fa492267fc2ef67f65a4dffbf2c85dec9f (patch)
tree5e7939b12b06c982923043bba367c53f770090f6
parent9754ffb24cc8dd7417c95a08b2967c5411e25944 (diff)
parent156c1445f3ed2c8fa860057709c230b6d119a958 (diff)
downloadphp-sparkpost-6a3715fa492267fc2ef67f65a4dffbf2c85dec9f.zip
php-sparkpost-6a3715fa492267fc2ef67f65a4dffbf2c85dec9f.tar.gz
php-sparkpost-6a3715fa492267fc2ef67f65a4dffbf2c85dec9f.tar.bz2
Add examples for cc/bcc
-rw-r--r--examples/transmission/send_with_bcc.php58
-rw-r--r--examples/transmission/send_with_cc.php62
2 files changed, 120 insertions, 0 deletions
diff --git a/examples/transmission/send_with_bcc.php b/examples/transmission/send_with_bcc.php
new file mode 100644
index 0000000..ce67862
--- /dev/null
+++ b/examples/transmission/send_with_bcc.php
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * For a more detailed explanation of how cc/bcc work with SparkPost, please
+ * check out this article: https://support.sparkpost.com/customer/portal/articles/1948014
+ */
+
+namespace Examples\Transmisson;
+
+require_once dirname(__FILE__).'/../bootstrap.php';
+
+//pull in API key config
+$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
+$config = json_decode($configFile, true);
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+
+$httpAdapter = new Guzzle6HttpAdapter(new Client());
+$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
+
+try {
+ $results = $sparky->transmission->send([
+ 'from' => [
+ 'name' => 'From Envelope',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'html' => '<p>An example email using bcc with SparkPost to the {{recipient_type}} recipient.</p>',
+ 'text' => 'An example email using bcc with SparkPost to the {{recipient_type}} recipient.',
+ 'subject' => 'Example email using bcc',
+ 'recipients' => [
+ [
+ 'address' => [
+ 'name' => 'Original Recipient',
+ 'email' => 'original.recipient@example.com',
+ ],
+ 'substitution_data' => [
+ 'recipient_type' => 'Original'
+ ]
+ ],
+ [
+ 'address' => [
+ 'email' => 'bcc.recipient@example.com',
+ 'header_to' => '"Original Recipient" <original.recipient@example.com>',
+ ],
+ 'substitution_data' => [
+ 'recipient_type' => 'BCC'
+ ]
+ ],
+ ],
+ ]);
+ echo 'Congrats! You sent an email with bcc using SparkPost!';
+} catch (\Exception $exception) {
+ echo $exception->getAPIMessage()."\n";
+ echo $exception->getAPICode()."\n";
+ echo $exception->getAPIDescription()."\n";
+}
diff --git a/examples/transmission/send_with_cc.php b/examples/transmission/send_with_cc.php
new file mode 100644
index 0000000..fa1d9e9
--- /dev/null
+++ b/examples/transmission/send_with_cc.php
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * For a more detailed explanation of how cc/bcc work with SparkPost, please
+ * check out this article: https://support.sparkpost.com/customer/portal/articles/1948014
+ */
+
+namespace Examples\Transmisson;
+
+require_once dirname(__FILE__).'/../bootstrap.php';
+
+//pull in API key config
+$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
+$config = json_decode($configFile, true);
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+
+$httpAdapter = new Guzzle6HttpAdapter(new Client());
+$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
+
+try {
+ $results = $sparky->transmission->send([
+ 'from' => [
+ 'name' => 'From Envelope',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'html' => '<p>An example email using cc with SparkPost to the {{recipient_type}} recipient.</p>',
+ 'text' => 'An example email using cc with SparkPost to the {{recipient_type}} recipient.',
+ 'subject' => 'Example email using cc',
+ 'recipients' => [
+ [
+ 'address' => [
+ 'name' => 'Original Recipient',
+ 'email' => 'original.recipient@example.com',
+ ],
+ 'substitution_data' => [
+ 'recipient_type' => 'Original'
+ ]
+ ],
+ [
+ 'address' => [
+ 'name' => 'Carbon Copy Recipient',
+ 'email' => 'cc.recipient@example.com',
+ 'header_to' => '"Original Recipient" <original.recipient@example.com>',
+ ],
+ 'substitution_data' => [
+ 'recipient_type' => 'CC'
+ ]
+ ],
+ ],
+ 'customHeaders' => [
+ 'CC' => '"Carbon Copy Recipient" <cc.recipient@example.com>'
+ ]
+ ]);
+ echo 'Congrats! You sent an email with cc using SparkPost!';
+} catch (\Exception $exception) {
+ echo $exception->getAPIMessage()."\n";
+ echo $exception->getAPICode()."\n";
+ echo $exception->getAPIDescription()."\n";
+}