Search
Search
Search
Search
Information
Information
Light
Dark
Open actions menu
Basic upload method
Bypass upload method
Tips!
If you encounter an error (by firewall) while uploading using both methods,
try changing extension of the file before uploading it and rename it right after.
This uploader supports multiple file upload.
Submit
~
var
www
multi-event-cfp.bitkit.dk
httpdocs
app
Http
Controllers
File Content:
SendGridHookController.php
<?php namespace App\Http\Controllers; use App\Models\EmailLog; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; class SendGridHookController extends Controller { public function handleEvents(Request $request) { try { $events = $request->all(); foreach ($events as $event) { $this->processEvent($event); } return response()->json(['status' => 'success'], 200); } catch (\Exception $e) { Log::error('SendGrid webhook error: ' . $e->getMessage(), [ 'request' => $request->all(), 'trace' => $e->getTraceAsString() ]); return response()->json(['status' => 'error'], 500); } } private function processEvent($event) { $messageId = $event['sg_message_id'] ?? null; $smtpId = $event['smtp-id'] ?? null; $email = $event['email'] ?? null; if (!$email) { return; } // Try to find by message ID first $emailLog = null; if ($messageId) { $emailLog = EmailLog::where('sendgrid_message_id', $messageId)->first(); } // Try SMTP-ID as backup if (!$emailLog && $smtpId) { $emailLog = EmailLog::where('smtp_id', $smtpId)->first(); } // If not found, try to find by recipient + subject (more unique) if (!$emailLog) { $subject = $this->getSubjectFromEvent($event); $emailLog = EmailLog::where('recipient', $email) ->where('status', 'processing') ->where(function($query) { $query->where('created_at', '>=', now()->subMinutes(10)) ->orWhere('updated_at', '>=', now()->subMinutes(10)); }) ->whereNull('sendgrid_message_id') ->when($subject, function ($query, $subject) { return $query->where('subject', 'LIKE', '%' . substr($subject, 0, 50) . '%'); }) ->orderBy('created_at', 'desc') ->first(); } if (!$emailLog) { return; } // Update message ID if we found the email if ($messageId && !$emailLog->sendgrid_message_id) { $emailLog->sendgrid_message_id = $messageId; } switch ($event['event']) { case 'delivered': $emailLog->update([ 'status' => 'success', 'sent_at' => now(), 'sendgrid_message_id' => $messageId, 'smtp_id' => $smtpId ]); break; case 'bounce': case 'dropped': case 'blocked': $emailLog->update([ 'status' => 'failed', 'failed_at' => now(), 'failure_reason' => $event['reason'] ?? $event['event'], 'failure_details' => $event, 'sendgrid_message_id' => $messageId, 'smtp_id' => $smtpId ]); break; } } private function getSubjectFromEvent($event) { // Try to extract subject from event data if available return $event['subject'] ?? null; } public function test() { Log::info('SendGrid webhook test called'); return response()->json(['status' => 'webhook working'], 200); } }
Edit
Download
Unzip
Chmod
Delete