Requires the Mautic Simple Mail plugin to be installed.
BarnebysMautic\Auth::initializeHttpBasic('username', 'password');
BarnebysMautic\Api::setBaseUrl('https://my.mautic.domain/api');
BarnebysMautic\Auth::initializeOAuth2
try {
$data = BarnebysMautic\Api::getContactIdByMail('some@email.com');
} catch (BarnebysMautic\Exception\ContactNotFoundException $exception) {
// Handle error
}
BarnebysMautic\Api::createContact($email, array $fields = [);
Updating a contact will do a PATCH and only update specified fields in the array.
BarnebysMautic\Api::updateContact($email, array $fields = [);
When sending emails you can with ease use sendToContact
and just set the email and a templateId.
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.
When sending values contain HTML and to disable Mautic HTML escaper set the 4th parameter to true.
$tokens = [
'custom_content' => 'This will value will be available in mautic as {custom_content}'
];
sendToContact($mail, $templateId, $tokens)
$tokens = [
'html_content' => '<span>This html content will not be escpaed</span>'
];
sendToContact($mail, $templateId, $tokens, true)
getContactIdByMail($mail)
sendToLead($mail, $templateId, array $tokens = [], $html = false)
sendToContact($mail, $templateId, array $tokens = [], $html = false)