Repository navigation
feat: send transactional email with emails()->send() #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+3,218
−94
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d06b4cf
feat: send transactional email with emails()->send()
Silthus 45341fa
fix: resolve the email User-Agent default inside the constructor
Silthus 6a732b9
docs: say a status read answers not_found right after a send
Silthus 181ed05
docs: say flag loading still sends the secret key to host
Silthus d5e5a2c
docs: show the proxy setup that keeps the secret key off host
Silthus b870c10
fix: send no retry after the client shut down during the wait
Silthus 15126f7
docs: qualify the Client class in the proxy example
Silthus c989580
fix: wait out the full retry delay when a signal cuts the sleep short
Silthus 6dbca5a
fix: keep the retry deadline on a monotonic clock
Silthus 03090d8
test: the retry wait follows the monotonic timer when the wall clock …
Silthus c034daa
fix: throw an EmailError when the curl extension is missing
Silthus df1d635
test: keep the no-curl test within the line limit
Silthus d96fa5d
fix: read an HTTP-date Retry-After in UTC
Silthus 84e9c9a
fix: stop reading an email reply over 1 MiB
Silthus 6abff5e
fix: clamp a numeric Retry-After before converting it to milliseconds
Silthus 4676fe0
fix(emails): keep a huge Retry-After inside an int on 32-bit PHP
Silthus 6c395aa
fix(emails): keep retry timing inside an int on 32-bit PHP
Silthus 00abb30
fix(emails): escape control characters in logged send warnings
Silthus c0cfc6b
fix(emails): skip the retry wait when the client closed during the re…
Silthus a123195
fix(emails): clamp a Retry-After too long for a float instead of drop…
Silthus 8efe315
fix(emails): check email options when the client is built, and leave …
Silthus b2a1c5c
fix(emails): refuse a non-integer email option, and say the reasons t…
Silthus 86447e6
fix(emails): drop the remaining private and test comments
Silthus aa6a0a4
fix(emails): name the transactional_email scopes for sends and status…
Silthus ccc3a54
docs(emails): rewrite the release note for transactional email
Silthus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| "posthog-php": minor | ||
| --- | ||
|
|
||
| The new `emails()` sends transactional email from your PHP code and reads each email's delivery status. | ||
|
|
||
| ```php | ||
| PostHog::init('phc_...', ['host' => 'https://us.i.posthog.com'], secretKey: 'phs_...'); | ||
|
|
||
| $result = PostHog::emails()->send([ | ||
| 'to' => 'user@example.com', | ||
| 'distinct_id' => 'user_123', | ||
| 'template_key' => 'password-reset', | ||
| 'subject' => 'Reset your password', | ||
| 'html' => $renderedHtml, | ||
| ]); | ||
|
|
||
| // 'delivered', 'bounced', ... | ||
| $status = PostHog::emails()->get($result->getId())->getStatus(); | ||
| ``` | ||
|
|
||
| You can also send a template made in PostHog by its `template_id`. | ||
|
|
||
| You need a project secret API key, the kind that starts with `phs_`. Create one under **Project secret API keys** in your project settings. Set its **Transactional email** scope to Write to send emails, or to Read for a key that only reads statuses. Pass it to the client as `secretKey`. Set the `app_host` option to your PostHog app URL when you self-host PostHog or send through a reverse proxy. The client also loads feature flags with this key when it starts, so give it **Feature flags: Read** too, or it logs an error each time a client starts. | ||
|
|
||
| PostHog records each email's delivery, opens and clicks on the person with that `distinct_id`. It groups every email with the same `template_key`, so you see their metrics and logs in one place. The SDK retries a request that hits a network error, a rate limit or an outage twice by default. Every send carries an idempotency key, so a retry never sends the email twice. Pass your own `idempotency_key`, such as `welcome:user_123`, and your job runner's retries are safe too. | ||
|
|
||
| A send with your own content also takes `from`, `reply_to` and `'capture_engagement' => false`. Set the `migrated_from` option to tell PostHog which email provider you moved from. A failed call throws a `PostHog\EmailError`. Its `getErrorCode()` returns PostHog's code, and `getStatusCode()` returns the HTTP status. | ||
|
|
||
| Docs: [Send transactional emails with PHP](https://posthog.com/docs/workflows/transactional-emails/php) and the [transactional email overview](https://posthog.com/docs/workflows/transactional-emails). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.