Skip to content

Commit

Permalink
test mode logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Mar 6, 2024
1 parent 04c0b2f commit 59c9378
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

**v0.1.0-alpha.3:**
- `README.md`: notice about test mode
- Support for test mode logging

**v0.1.0-alpha.2:**
- `README.md` cleanup (listing of components)
- `Image` component now requires only `src`; the other params are optional
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ There are more examples in the [examples](examples) folder ✨
> [!NOTE]
> 🚧 **The SDK is not stable yet.** This API might change as more features are added. Please watch the repo for the changes in the [CHANGELOG](CHANGELOG.md).
## 🏗 Debugging

You can generate _test API keys_ by activating the **Test Mode** in your dashboard. By using these keys, you'll be able to view your fully rendered emails without actually sending them.

When you use a test API key in your SDK, the following output will appear in your logs when you try to send an email:

```log
Templateless [TEST MODE]: Emailed user@example.com, preview: https://tmpl.sh/ATMxHLX4r9aE
```

The preview link will display the email, but you must be logged in to Templateless to view it.

## 🔳 Components

Emails are crafted programmatically by making function calls. There's no dealing with HTML or drag-and-drop builders.
Expand Down Expand Up @@ -251,7 +263,7 @@ If you'd like your recipients to be able to read the email in a browser, you can

You can optionally provide the text for the link. If none is provided, default is used: "View in browser"

**This will make the email public to anyone that has access to the link.**
**Anyone who knows the link will be able to see the email.**

```php
Content::builder()
Expand Down
7 changes: 7 additions & 0 deletions src/Templateless.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function sendMany($emails)
} elseif ($statusCode === 200) {
$responseText = $response->getBody()->getContents();
$emailResponse = json_decode($responseText, true);

if (!empty($emailResponse['previews'])) {
foreach ($emailResponse['previews'] as $preview) {
echo "Templateless [TEST MODE]: Emailed {$preview['email']}, preview: https://tmpl.sh/{$preview['preview']}\n";
}
}

if ($emailResponse !== null && isset($emailResponse['emails'])) {
return new EmailResponse($emailResponse['emails']);
} else {
Expand Down

0 comments on commit 59c9378

Please sign in to comment.