Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added attachment example
- Loading branch information
Showing
20 changed files
with
69 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
.settings | ||
.buildpath | ||
test/output/ | ||
examples/example-options.json | ||
.idea | ||
/composer.phar | ||
test.php |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
<?php | ||
|
||
require_once dirname(__FILE__).'/../vendor/autoload.php'; | ||
|
||
//pull in library options | ||
$optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json'); | ||
$options = json_decode($optionsFile, true); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
55 changes: 55 additions & 0 deletions
55
examples/transmissions/create_transmission_with_attachment.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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"]); | ||
|
||
$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"; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.