-
Notifications
You must be signed in to change notification settings - Fork 9
/
send-email.php
56 lines (39 loc) · 1.54 KB
/
send-email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*******************************************************************************
Captura informações de um POST de um webhook e envia para a API do Mautic
********************************************************************************
*
* @property Powertic
* @autor Luiz Eduardo - [email protected]
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @mautic-min-version 2.10.0
*
*/
include __DIR__ . '/vendor/autoload.php';
use Mautic\Auth\ApiAuth;
use Mautic\MauticApi;
session_start();
include "credentials.php";
echo 'processando ....';
// Conecta no objeto de autenticação através da BasicAuth
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth( $credentials, 'BasicAuth' );
// Instanciando um novo objeto Mautic
$api = new MauticApi();
$emailApi = $api->newApi( 'emails', $auth, $mauticUrl );
$contactApi = $api->newApi( 'contacts', $auth, $mauticUrl );
$dados = $_POST;
// Pesquisa o contato pelo e-mail | "email:[email protected]"
$contact_id = $dados['contact_id'];
$response = $contactApi->getList( "ids:$contact_id" );
$json = json_encode( $response );
$decodedJson = json_decode( $json, true );
$id = 0;
$mautic_data = array();
$mautic_data = $decodedJson["contacts"][$contact_id]["fields"][ "all"];
$ids = explode(",", $dados["ids"]);
$email_id = $dados["email_id"];
foreach ($ids as $contact_id):
$r = $emailApi->sendToContact($email_id, $contact_id, array( 'tokens' => $mautic_data ) );
var_dump($r);
endforeach;