summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/transmissions/create_transmission_with_attachment.php58
-rw-r--r--examples/transmissions/sparkpost.pngbin0 -> 6953 bytes
2 files changed, 58 insertions, 0 deletions
diff --git a/examples/transmissions/create_transmission_with_attachment.php b/examples/transmissions/create_transmission_with_attachment.php
new file mode 100644
index 0000000..4186806
--- /dev/null
+++ b/examples/transmissions/create_transmission_with_attachment.php
@@ -0,0 +1,58 @@
+<?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());
+
+/*
+ * configure options in example-options.json
+ */
+$sparky = new SparkPost($httpClient, $options);
+
+$filePath = dirname(__FILE__).'/';
+$fileName = 'sparkpost.png';
+$fileType = mime_content_type($filePath.$fileName);
+$fileData = base64_encode(file_get_contents($filePath.$fileName));
+
+$promise = $sparky->transmissions->post([
+ 'content' => [
+ 'from' => [
+ 'name' => 'SparkPost Team',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'subject' => 'Mailing With Attachment From PHP',
+ 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email with an attachment!</p></body></html>',
+ 'text' => 'Congratulations, {{name}}! You just sent an email with an attachment',
+ 'attachments' => [
+ [
+ 'name' => $fileName,
+ 'type' => $fileType,
+ 'data' => $fileData,
+ ],
+ ],
+ ],
+ '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";
+}
diff --git a/examples/transmissions/sparkpost.png b/examples/transmissions/sparkpost.png
new file mode 100644
index 0000000..140a146
--- /dev/null
+++ b/examples/transmissions/sparkpost.png
Binary files differ