I am using Amazon SES service. But I couldn't understand how will I track the bounce email messages using PHP and keep store those email logs in database. I have a reference link of Amazon blog, but the solution given there is on C#(http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/Handling-Bounces-and-Complaints). Need help and assistance. Thank you.
STEPS TO FOLLOW
Create SNS Topic
Create subscription
Confirm subscription
Code
class AmazonController extends Controller
{
public function handleBounceOrComplaint(Request $request)
{
Log::info($request->json()->all());
$data = $request->json()->all();
if($request->json('Type') == 'SubscriptionConfirmation')
Log::info("SubscriptionConfirmation came at: ".$data['Timestamp']);
if($request->json('Type') == 'Notification'){
$message = $request->json('Message');
switch($message['notificationType']){
case 'Bounce':
$bounce = $message['bounce'];
foreach ($bounce['bouncedRecipients'] as $bouncedRecipient){
$emailAddress = $bouncedRecipient['emailAddress'];
$emailRecord = WrongEmail::firstOrCreate(['email' => $emailAddress, 'problem_type' => 'Bounce']);
if($emailRecord){
$emailRecord->increment('repeated_attempts',1);
}
}
break;
case 'Complaint':
$complaint = $message['complaint'];
foreach($complaint['complainedRecipients'] as $complainedRecipient){
$emailAddress = $complainedRecipient['emailAddress'];
$emailRecord = WrongEmail::firstOrCreate(['email' => $emailAddress, 'problem_type' => 'Complaint']);
if($emailRecord){
$emailRecord->increment('repeated_attempts',1);
}
}
break;
default:
// Do Nothing
break;
}
}
return Response::json(['status' => 200, "message" => 'success']);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With