-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpepipost.php
93 lines (82 loc) · 3.54 KB
/
pepipost.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* File: webhooks/pepipost.php
* Description: This file provides an endpoint for Pepipost's API.
* Version: 0.1
* Contributors:
* Pepipost API https://docs.pepipost.com/
* Tabrez Shaikh http://tabrez.me/
* Blaine Moore http://blainemoore.com
*/
/**
* Example output:
{
"TRANSID":"14551290015805717",
"RCPTID":"12",
"RESPONSE":"smtp;250 2.0.0 Ok: queued as 824C61FBBB3\r",
"EMAIL":"toabc@abc.com",
"TIMESTAMP":"1455193720",
"CLIENTID":"18654",
"FROMADDRESS":"fromabc@abc.com",
"EVENT":"sent",
"USERAGENT":"1468"
}
// for debugging
function webhooks_debug($msg){
$fp =fopen('webhooklog.txt','a');
fwrite($fp,"\nmsg($msg)<br />\n");
fclose($fp);
}
*/
include_once('includes/config.php');
$webhooks_provider = "Pepipost";
$HTTP_RAW_POST_DATA = @file_get_contents('php://input');
$json_payload = urldecode($HTTP_RAW_POST_DATA);
$events = json_decode($json_payload, true);
foreach ($events as $event) {
if (filter_var($event['EMAIL'],FILTER_VALIDATE_EMAIL)) {
switch($event["EVENT"])
{
case "sent": event_send($event); break;
case "opened": event_open($event); break;
case "clicked": event_click($event); break;
case "bounced":
if($event['BOUNCE_TYPE'] === 'HARDBOUNCE') {
webhooks_hard_bounce($event['EMAIL']);
}
else {
webhooks_soft_bounce($event['EMAIL']);
}
break;
case "unsubscribed": event_unsubscribe($event); break;
case "spam": webhooks_spam_report($event['EMAIL']); break;
case "dropped": event_dropped($event); break;
case "invalid": event_invalid($event); break;
default: webhooks_debug(" == Invalid category: '".$event["EVENT"]."' for: ".$event["EMAIL"]." ==");
}
} else { // invalid email address
webhooks_debug(" == Invalid email address: '".$event['EMAIL']."' ==");
} // if (filter_var($event["recipient"],FILTER_VALIDATE_EMAIL))
}
//----------------------------------------------------------------------------------//
// PEPIPOST EVENTS UNHANDLED BY WEBHOOKS
//----------------------------------------------------------------------------------//
function event_open($event) {
webhooks_debug("Email opened: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_open($event)
function event_click($event) {
webhooks_debug("Email clicked: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_click($event)
function event_unsubscribe($event) {
webhooks_debug("Email unsubscribed: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_unsubscribe($event)
function event_send($event) {
webhooks_debug("Email sent: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_send($event)
function event_dropped($event) {
webhooks_debug("Email dropped: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_dropped($event)
function event_invalid($event) {
webhooks_debug("Email invalid: " . $event['EMAIL'] . " (" . $event['TRANSID'] . ")\t(Currently unhandled by Webhooks)");
} // function event_invalid($event)
//----------------------------------------------------------------------------------//