diff options
-rw-r--r-- | README.md | 38 | ||||
-rw-r--r-- | examples/transmission/configuration_based.php | 52 | ||||
-rw-r--r-- | examples/transmission/get_all_transmissions.php | 28 | ||||
-rw-r--r-- | examples/transmission/get_transmission.php | 10 | ||||
-rw-r--r-- | examples/transmission/rfc822.php | 10 | ||||
-rw-r--r-- | examples/transmission/stored_recipients_inline_content.php | 10 | ||||
-rw-r--r-- | examples/transmission/stored_template_send.php | 10 | ||||
-rw-r--r-- | lib/MessageSystems/Transmission.php | 7 |
8 files changed, 77 insertions, 88 deletions
@@ -11,7 +11,7 @@ To get an API Key, please log in to your SparkPost account and generate one in t The recommended way to install the SparkPost PHP SDK is through composer. ``` # Install Composer -curl -sS https:// getcomposer.org/installer | php +curl -sS https://getcomposer.org/installer | php ``` Next, run the Composer command to install the SparkPost PHP SDK: ``` @@ -24,25 +24,19 @@ require 'vendor/autoload.php'; ## Getting Started: Your First Mailing ``` -$sparkpost = new SparkPost(["key"=>"YOUR API KEY"]); - -$transmission = $sparkpost->transmission(); - -// Add some template data to your email -$transmission->setCampaign('first-mailing')-> - setReturnPath('bounces@sparkpost.com')-> - setFrom('you@your-company.com')-> - setSubject('First SDK Mailing')-> - setHTMLContent('<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>')-> - setTextContent('Congratulations, {{name}}!! You just sent your very first mailing!')-> - setSubstitutionData(['name'=>'YOUR FIRST NAME']); - -// Pick someone to receive your email -$transmission->addRecipient(['address'=>['name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' ]]); - -// Send it off into the world! +SparkPost::setConfig(["key"=>"YOUR API KEY"]); + try { - $response = $transmission->send(); + // Build your email and send it! + Transmission::send(['campaign'=>'first-mailing', + 'from'=>'you@your-company.com', + 'subject'=>'First SDK Mailing', + 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', + 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!', + 'substitutionData'=>['name'=>'YOUR FIRST NAME'], + 'recipients'=>[['address'=>['name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' ]]] + ]); + echo 'Woohoo! You just sent your first mailing!'; } catch (Exception $err) { echo 'Whoops! Something went wrong'; @@ -59,16 +53,12 @@ try { ### General * You _must_ provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]` * The SDK's features are namespaced under the various SparkPost API names. -* There are two ways to provide values to each namespace of the SDK: - - On instantiation, you pass in a well-formed object (See examples). - - You use the helper methods to incrementally create a well-formed object. These helper methods are chainable (See examples). ### Transmissions * If you specify a stored recipient list and inline recipients in a Transmission, whichever was provided last will be used. - * If you call addRecipient and then useRecipientList, the latter will overwrite the former. * If you specify HTML and/or Plain Text content and then provide RFC-822 encoded content, you will receive an error. * RFC-822 content is not valid with any other content type. -* If you specify a stored template and also provide inline content via setHTMLContent or setTextContent, you will receive an error. +* If you specify a stored template and also provide inline content via `html` or `text`, you will receive an error. * By default, open and click tracking are enabled for a transmission. * By default, a transmission will use the published version of a stored template. diff --git a/examples/transmission/configuration_based.php b/examples/transmission/configuration_based.php index 366434f..7f93b05 100644 --- a/examples/transmission/configuration_based.php +++ b/examples/transmission/configuration_based.php @@ -1,32 +1,32 @@ <?php namespace Examples\Transmisson; - require_once (dirname(__FILE__).'/../bootstrap.php'); +require_once (dirname(__FILE__).'/../bootstrap.php'); - use MessageSystems\SparkPost; - use MessageSystems\Transmission; +use MessageSystems\SparkPost; +use MessageSystems\Transmission; - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::send([ + "returnPath"=>"return@example.com", + "from"=>"From Envelope <from@example.com>", + "html"=>"<p>Hello World!</p>", + "text"=>"Hello World!", + "subject"=>"Example Email", + "recipients"=>[ + [ + "address"=>[ + "email"=>"john.doe@example.com" + ] + ] + ] + ]); + echo 'Congrats you can use your SDK!'; - try { - $results = Transmission::send([ - "returnPath"=>"return@example.com", - "from"=>"From Envelope <from@example.com>", - "html"=>"<p>Hello World!</p>", - "text"=>"Hello World!", - "subject"=>"Example Email", - "recipients"=>[ - [ - "address"=>[ - "email"=>"jordan.nornhold@rackspace.messagesystems.com" - ] - ] - ] - ]); - echo 'Congrats you can use your SDK!'; - - var_dump(Transmission::$structure); - } catch (\Exception $exception) { - echo $exception->getMessage(); - } + var_dump(Transmission::$structure); +} catch (\Exception $exception) { + echo $exception->getMessage(); +} ?>
\ No newline at end of file diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php index 1425e65..754a6fc 100644 --- a/examples/transmission/get_all_transmissions.php +++ b/examples/transmission/get_all_transmissions.php @@ -1,17 +1,17 @@ <?php namespace Examples\Transmisson; - require_once (dirname(__FILE__).'/../bootstrap.php'); - - use MessageSystems\SparkPost; - use MessageSystems\Transmission; - - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); - - try { - $results = Transmission::all(); - echo 'Congrats you can use your SDK!'; - } catch (\Exception $exception) { - echo $exception->getMessage(); - } +require_once (dirname(__FILE__).'/../bootstrap.php'); + +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); + +try { + $results = Transmission::all(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} ?>
\ No newline at end of file diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php index 55cfe79..b85d814 100644 --- a/examples/transmission/get_transmission.php +++ b/examples/transmission/get_transmission.php @@ -1,11 +1,11 @@ <?php namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); - use MessageSystems\SparkPost; - use MessageSystems\Transmission; - - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); try { $results = Transmission::find('Your Transmission Id'); diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php index e2b7353..1927382 100644 --- a/examples/transmission/rfc822.php +++ b/examples/transmission/rfc822.php @@ -1,11 +1,11 @@ <?php namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); - use MessageSystems\SparkPost; - use MessageSystems\Transmission; - - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); try { $results = Transmission::send([ diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php index a545122..f09ca63 100644 --- a/examples/transmission/stored_recipients_inline_content.php +++ b/examples/transmission/stored_recipients_inline_content.php @@ -1,13 +1,11 @@ <?php namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); - use MessageSystems\SparkPost; - use MessageSystems\Transmission; - - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); - +use MessageSystems\SparkPost; +use MessageSystems\Transmission; +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); try { diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php index 4d58c70..298ba69 100644 --- a/examples/transmission/stored_template_send.php +++ b/examples/transmission/stored_template_send.php @@ -1,11 +1,11 @@ <?php namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); - use MessageSystems\SparkPost; - use MessageSystems\Transmission; - - $key = 'YOURAPIKEY'; - SparkPost::setConfig(['key'=>$key]); +use MessageSystems\SparkPost; +use MessageSystems\Transmission; + +$key = 'YOURAPIKEY'; +SparkPost::setConfig(['key'=>$key]); try { $results = Transmission::send([ diff --git a/lib/MessageSystems/Transmission.php b/lib/MessageSystems/Transmission.php index af8b722..71b54a0 100644 --- a/lib/MessageSystems/Transmission.php +++ b/lib/MessageSystems/Transmission.php @@ -38,9 +38,10 @@ class Transmission { 'email_rfc822'=>null ], 'options'=>[ - 'open_tracking'=>null, - 'click_tracking'=>null - ] + 'open_tracking'=>true, + 'click_tracking'=>true + ], + 'use_draft_template'=>false ]; /** |