|
1 | | -php-sdk |
2 | | -======= |
| 1 | +# SparkPost PHP SDK |
| 2 | +The official PHP binding for your favorite SparkPost APIs! |
| 3 | + |
| 4 | +Before using this library, you must have a valid API Key. |
| 5 | + |
| 6 | +To get an API Key, please log in to your SparkPost account and generate one in the Settings page. |
| 7 | + |
| 8 | +## Installation |
| 9 | +The recommended way to install the SparkPost PHP SDK is through composer. |
| 10 | +``` |
| 11 | +# Install Composer |
| 12 | +curl -sS https://getcomposer.org/installer | php |
| 13 | +``` |
| 14 | +Next, run the Composer command to install the SparkPost PHP SDK: |
| 15 | +``` |
| 16 | +composer require messagesystems/php-sdk |
| 17 | +``` |
| 18 | +After installing, you need to require Composer's autoloader: |
| 19 | +``` |
| 20 | +require 'vendor/autoload.php'; |
| 21 | +``` |
| 22 | + |
| 23 | +## Getting Started: Your First Mailing |
| 24 | +``` |
| 25 | +SparkPost::setConfig(["key"=>"YOUR API KEY"]); |
| 26 | +
|
| 27 | +try { |
| 28 | + // Build your email and send it! |
| 29 | + Transmission::send(['campaign'=>'first-mailing', |
| 30 | + 'from'=>'you@your-company.com', |
| 31 | + 'subject'=>'First SDK Mailing', |
| 32 | + 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', |
| 33 | + 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!', |
| 34 | + 'substitutionData'=>['name'=>'YOUR FIRST NAME'], |
| 35 | + 'recipients'=>[['address'=>['name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' ]]] |
| 36 | + ]); |
| 37 | +
|
| 38 | + echo 'Woohoo! You just sent your first mailing!'; |
| 39 | +} catch (Exception $err) { |
| 40 | + echo 'Whoops! Something went wrong'; |
| 41 | + var_dump($err); |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## Learn More |
| 46 | +* For more detailed examples, check our examples: |
| 47 | + * [Transmissions](https://github.com/MessageSystems/php-sdk/tree/master/examples/transmission/) |
| 48 | +* Read our REST API documentation - <http://www.sparkpost.com/docs/introduction> |
| 49 | + |
| 50 | +## Tips and Tricks |
| 51 | +### General |
| 52 | +* You _must_ provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]` |
| 53 | +* The SDK's features are namespaced under the various SparkPost API names. |
| 54 | + |
| 55 | +### Transmissions |
| 56 | +* If you specify a stored recipient list and inline recipients in a Transmission, you will recieve an error. |
| 57 | +* If you specify HTML and/or Plain Text content and then provide RFC-822 encoded content, you will receive an error. |
| 58 | + * RFC-822 content is not valid with any other content type. |
| 59 | +* If you specify a stored template and also provide inline content via `html` or `text`, you will receive an error. |
| 60 | +* By default, open and click tracking are enabled for a transmission. |
| 61 | +* By default, a transmission will use the published version of a stored template. |
| 62 | + |
| 63 | +## Development |
| 64 | + |
| 65 | +### Setup |
| 66 | +We use [Robo](http://robo.li/) for our task runner. |
| 67 | + |
| 68 | +Run `composer install` inside the directory to install dependecies and development tools including Robo. |
| 69 | + |
| 70 | +### Testing |
| 71 | +Once all the dependencies are installed, you can execute the unit tests using `vendor\bin\robo test` |
| 72 | + |
| 73 | +### Contributing |
| 74 | +Guidelines for adding issues |
| 75 | + |
| 76 | +Submitting pull requests |
| 77 | + |
| 78 | +Signing our CLA |
| 79 | + |
| 80 | +Our coding standards |
0 commit comments