|
10 | 10 |
|
11 | 11 | $httpClient = new GuzzleAdapter(new Client()); |
12 | 12 |
|
13 | | -$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]); |
| 13 | +// In these examples, fetch API key from environment variable |
| 14 | +$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]); |
| 15 | + |
| 16 | +$template_name = "PHP example template"; |
| 17 | +$template_id = "PHP-example-template"; |
| 18 | + |
| 19 | +// put your own sending domain here |
| 20 | +$sending_domain = "steve2-test.trymsys.net"; |
| 21 | + |
| 22 | +// Valid short template content examples |
| 23 | +$plain_text = 'Write your text message part here.'; |
| 24 | + |
| 25 | +$html = <<<HTML |
| 26 | +<!DOCTYPE html> |
| 27 | +<html lang="en"> |
| 28 | +<body> |
| 29 | + <p><strong>Write your HTML message part here</strong></p> |
| 30 | +</body> |
| 31 | +</html> |
| 32 | +HTML; |
| 33 | + |
| 34 | +$amp_html = <<<HTML |
| 35 | +<!doctype html> |
| 36 | +<html ⚡4email> |
| 37 | +<head> |
| 38 | + <meta charset="utf-8"> |
| 39 | + <style amp4email-boilerplate>body{visibility:hidden}</style> |
| 40 | + <script async src="https://cdn.ampproject.org/v0.js"></script> |
| 41 | +</head> |
| 42 | +<body> |
| 43 | +Hello World! Let's get started using AMP HTML together! |
| 44 | +</body> |
| 45 | +</html> |
| 46 | +HTML; |
14 | 47 |
|
15 | 48 | $promise = $sparky->request('POST', 'templates', [ |
16 | | - 'name' => 'PHP example template', |
| 49 | + 'name' => $template_name, |
| 50 | + 'id' => $template_id, |
17 | 51 | 'content' => [ |
18 | | - 'from' => 'from@YOUR_DOMAIN', |
| 52 | + 'from' => "from@$sending_domain", |
19 | 53 | 'subject' => 'Your Subject', |
20 | | - 'html' => '<b>Write your message here.</b>', |
| 54 | + 'text' => $plain_text, |
| 55 | + 'html' => $html, |
| 56 | + 'amp_html' => $amp_html, |
21 | 57 | ], |
22 | 58 | ]); |
23 | 59 |
|
|
0 commit comments