Skip to content

Commit 937af68

Browse files
authored
Merge pull request #2 from vikramsra/imran
#1 Fixed: HTML is not capturing and rendered preview
2 parents ca1648c + d9de920 commit 937af68

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
Route::middleware(['web'])->group(function () {
66
Route::get('/email-logs', [EmailLogController::class, 'index'])->name('email.logs.index');
77
Route::get('/email-logs/{id}', [EmailLogController::class, 'show'])->name('email.logs.show');
8-
8+
Route::get('/email-logs/{log}/body', [EmailLogController::class, 'body'])->name('email.logs.body');
99
});

src/Controllers/EmailLogController.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,35 @@
99
class EmailLogController extends Controller
1010
{
1111
public function index(Request $request)
12-
{
13-
// Start with a query builder
14-
$query = EmailLog::query();
12+
{
13+
// Start with a query builder
14+
$query = EmailLog::query();
1515

16-
// Apply filters if present
17-
if ($request->filled('recipient')) {
18-
$query->where('recipient', 'like', '%' . $request->recipient . '%');
19-
}
16+
// Apply filters if present
17+
if ($request->filled('recipient')) {
18+
$query->where('recipient', 'like', '%' . $request->recipient . '%');
19+
}
2020

21-
if ($request->filled('subject')) {
22-
$query->where('subject', 'like', '%' . $request->subject . '%');
23-
}
21+
if ($request->filled('subject')) {
22+
$query->where('subject', 'like', '%' . $request->subject . '%');
23+
}
2424

25-
if ($request->filled('sent_date')) {
26-
$query->whereDate('created_at', $request->sent_date);
27-
}
25+
if ($request->filled('sent_date')) {
26+
$query->whereDate('created_at', $request->sent_date);
27+
}
2828

29-
// Get paginated results with applied filters
30-
$logs = $query->paginate(10);
29+
// Get paginated results with applied filters
30+
$logs = $query->paginate(10);
3131

32-
if ($request->ajax()) {
33-
return view('emailLogs::partials.email_logs_table', compact('logs'))->render();
32+
if ($request->ajax()) {
33+
return view('emailLogs::partials.email_logs_table', compact('logs'))->render();
34+
}
35+
36+
return view('emailLogs::index', compact('logs'));
3437
}
3538

36-
return view('emailLogs::index', compact('logs'));
37-
}
39+
public function body(EmailLog $log)
40+
{
41+
return view('emailLogs::body', compact('log'));
42+
}
3843
}

src/Listeners/LogSentEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function handle(MessageSent $event)
4949
'cc' => $cc,
5050
'bcc' => $bcc,
5151
'subject' => $message->getSubject(),
52-
'body' => $message->getTextBody() ?? $message->getHtmlBody(),
52+
'body' => $message->getHtmlBody() ?? $message->getTextBody(),
5353
'headers' => $headers,
5454
'attachments' => $attachments, // Storing AWS links here
5555
]);

src/views/body.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{!! $log->body !!}

src/views/index.blade.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -13,6 +14,7 @@
1314
}
1415
</style>
1516
</head>
17+
1618
<body>
1719
<div class="container mt-5">
1820
<h2 class="mb-4 text-center">Email Logs</h2>
@@ -21,13 +23,16 @@
2123
<form id="filter-form" class="mb-4">
2224
<div class="row">
2325
<div class="col-md-3">
24-
<input type="text" id="recipient" name="recipient" class="form-control" placeholder="Recipient" value="{{ request('recipient') }}">
26+
<input type="text" id="recipient" name="recipient" class="form-control" placeholder="Recipient"
27+
value="{{ request('recipient') }}">
2528
</div>
2629
<div class="col-md-3">
27-
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject" value="{{ request('subject') }}">
30+
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject"
31+
value="{{ request('subject') }}">
2832
</div>
2933
<div class="col-md-3">
30-
<input type="date" id="sent_date" name="sent_date" class="form-control" value="{{ request('sent_date') }}">
34+
<input type="date" id="sent_date" name="sent_date" class="form-control"
35+
value="{{ request('sent_date') }}">
3136
</div>
3237
<div class="col-md-3">
3338
<button type="submit" class="btn btn-primary">Filter</button>
@@ -56,7 +61,7 @@
5661
<p><strong>BCC:</strong> <span id="log-bcc"></span></p>
5762
<p><strong>Subject:</strong> <span id="log-subject"></span></p>
5863
<p><strong>Body:</strong></p>
59-
<pre id="log-body"></pre>
64+
<iframe src="" id="log-body" class="w-100" style="height: 400px"></iframe>
6065
<p><strong>Attachments:</strong></p>
6166
<div id="log-attachments"></div>
6267
</div>
@@ -109,25 +114,27 @@ function fetchLogs() {
109114
110115
// JavaScript to handle the modal data population
111116
const logDetailModal = document.getElementById('logDetailModal');
112-
logDetailModal.addEventListener('show.bs.modal', function (event) {
117+
logDetailModal.addEventListener('show.bs.modal', function(event) {
113118
const button = event.relatedTarget;
114119
115120
// Extract data from the button attributes
121+
const id = button.getAttribute('data-id');
116122
const sender = button.getAttribute('data-sender');
117123
const recipient = button.getAttribute('data-recipient');
118124
const cc = button.getAttribute('data-cc') || 'N/A';
119125
const bcc = button.getAttribute('data-bcc') || 'N/A';
120126
const subject = button.getAttribute('data-subject');
121127
const body = button.getAttribute('data-body');
122128
const attachments = JSON.parse(button.getAttribute('data-attachments'));
129+
const url = '{{ route('email.logs.body', ':id') }}';
123130
124131
// Update the modal content
125132
document.getElementById('log-sender').textContent = sender;
126133
document.getElementById('log-recipient').textContent = recipient;
127134
document.getElementById('log-cc').textContent = cc;
128135
document.getElementById('log-bcc').textContent = bcc;
129136
document.getElementById('log-subject').textContent = subject;
130-
document.getElementById('log-body').textContent = body;
137+
document.getElementById('log-body').src = url.replace(':id', id);
131138
132139
// Handle attachments
133140
const attachmentsContainer = document.getElementById('log-attachments');
@@ -147,4 +154,5 @@ function fetchLogs() {
147154
});
148155
</script>
149156
</body>
157+
150158
</html>

0 commit comments

Comments
 (0)