diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 38 |
1 files changed, 14 insertions, 24 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. |