Skip to content

Instantly share code, notes, and snippets.

@tiagofrancafernandes
Created November 25, 2023 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagofrancafernandes/a7186e73bdcde2779cdf8429171079ef to your computer and use it in GitHub Desktop.
Save tiagofrancafernandes/a7186e73bdcde2779cdf8429171079ef to your computer and use it in GitHub Desktop.
dev mautic snippets

Se você está procurando uma ferramenta de código aberto para automação de email marketing em PHP, a Mautic pode ser uma boa opção.

A Mautic é uma plataforma de marketing de código aberto que permite que você automatize todas as suas campanhas de marketing, incluindo email marketing. Ela oferece recursos como segmentação de leads, rastreamento de campanhas, gestão de contatos e muito mais. Além disso, a Mautic também oferece uma API RESTful que permite que você integre a plataforma com outras ferramentas ou sistemas Source 1.

Aqui está um exemplo de como você pode usar a API da Mautic para enviar um email:

<?php
require 'vendor/autoload.php';

use Mautic\Auth\ApiAuth;
use Mautic\Auth\ApiAuthInterface;
use Mautic\Api\Contacts;

// Authenticate to Mautic
$settings = array(
   'baseUrl'     => 'http://your-mautic-instance.com', // Base URL of your Mautic instance
   'version'     => 'OAuth2', // Version of the OAuth can be OAuth2 or OAuth1a. OAuth2 is the default value.
   'clientKey'   => 'your_client_key', // Client/Consumer key from Mautic
   'clientSecret' => 'your_client_secret', // Client/Consumer secret key from Mautic
   'callback'    => 'your_callback_url', // Redirect URI/Callback URI for this script
);

// Initiate the auth object
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);

// Initiate contact object
$contactApi = $auth->newApi('contacts', $auth->getAccessToken(), $auth->getAccessTokenSecret());

// Create a contact
$contact = $contactApi->createContact(array(
   'firstname' => 'John',
   'lastname' => 'Doe',
   'email'    => 'john.doe@example.com',
));

// Send an email
$contactApi->sendEmail($contact['contact']['id'], 'your_email_template_id');
?>

Este exemplo cria um novo contato e envia um email para ele usando um modelo de email que você definiu no Mautic. Você precisará substituir 'your_client_key', 'your_client_secret', 'your_callback_url' e 'your_email_template_id' pelos valores apropriados para sua instância do Mautic Source 1.

Por favor, note que você precisará instalar a biblioteca PHP Mautic através do Composer antes de poder usar o código acima. Você pode fazer isso executando o seguinte comando no terminal:

composer require mautic/api-library

Espero que isso ajude! Se você tiver mais perguntas, sinta-se à vontade para perguntar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment