Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 13d85f1

Browse files
Updates README with more documentation
Fixes a more simple handling for tokens array
1 parent 187db55 commit 13d85f1

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,42 @@ BarnebysMautic\Auth::initializeOAuth2
1717

1818
### Fetch a contact id by email
1919
```
20-
$data = BarnebysMautic\Api::getContactIdByMail('[email protected]');
20+
try {
21+
$data = BarnebysMautic\Api::getContactIdByMail('[email protected]');
22+
} catch (BarnebysMautic\Exception\ContactNotFoundException $exception) {
23+
// Handle error
24+
}
25+
```
26+
27+
### Sending emails
28+
29+
When sending emails you can with ease use `sendToContact` and just set the email and a templateId.
30+
If you need to pass on some custom fields to be used in Mautic those can set as a key => value array for parameter 3.
31+
When sending values contain HTML and to disable Mautic HTML escaper set the 4th parameter to true.
32+
33+
##### Sending a email with custom fields
34+
35+
```
36+
$tokens = [
37+
'custom_content' => 'This will value will be available in mautic as {custom_content}'
38+
];
39+
40+
sendToContact($mail, $templateId, $tokens)
41+
```
42+
43+
##### Sending a email with html content
44+
45+
```
46+
$tokens = [
47+
'html_content' => '<span>This html content will not be escpaed</span>'
48+
];
49+
50+
sendToContact($mail, $templateId, $tokens, true)
2151
```
2252

2353
### Other available methods
2454
```
2555
getContactIdByMail($mail)
26-
sendToLead($mail, $templateId)
27-
sendToContact($mail, $templateId)
56+
sendToLead($mail, $templateId, array $tokens = [], $html = false)
57+
sendToContact($mail, $templateId, array $tokens = [], $html = false)
2858
```

src/Api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public static function sendToLead($email, $templateId, array $tokens = [], $html
8484
*/
8585
public static function sendToContact($email, $templateId, array $tokens = [], $html = false)
8686
{
87+
if (!isset($tokens['tokens'])) {
88+
$tokens = ['tokens' => $tokens];
89+
}
90+
8791
$contactId = self::getContactIdByMail($email);
8892

8993
$api = self::getApiInstance();

0 commit comments

Comments
 (0)