-
-
Save fukuball/fef99d0c75e460ce74c625d49416a9e8 to your computer and use it in GitHub Desktop.
Laravel 5.1 Controller that receives AWS SES Bounce and Complaint notifications sent via AWS SNS. It records the email addresses that bounced or complained in a database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function postBounceOrComplaint(Request $request, Mailer $mailer){ | |
Log::info($request->json()->all()); | |
if($request->json('Type') == 'SubscriptionConfirmation'){ | |
$client = new Client(); | |
$client->get($request->json('SubscribeURL')); | |
return response()->json(); | |
} | |
// | |
if($request->json('Type') == 'Notification'){ | |
$message = json_decode($request->json('Message')); | |
switch($message->notificationType){ | |
case 'Bounce': | |
$bounce = $message->bounce; | |
foreach ($bounce->bouncedRecipients as $bouncedRecipient){ | |
$emailAddress = $bouncedRecipient->emailAddress; | |
$emailRecord = ProblemEmail::firstOrCreate(['email_address' => $emailAddress]); | |
$emailRecord->incrementBounceCount(1); | |
}; | |
break; | |
case 'Complaint': | |
$complaint = $message->complaint; | |
foreach($complaint->complainedRecipients as $complainedRecipient){ | |
$emailAddress = $complainedRecipient->emailAddress; | |
$emailRecord = ProblemEmail::firstOrCreate(['email_address' => $emailAddress]); | |
$emailRecord->incrementComplainedCount(1); | |
} | |
break; | |
default: | |
// Do Nothing | |
break; | |
} | |
} | |
return response()->json(['message' => 'success']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment