Skip to content

Commit ccf30cf

Browse files
author
Ratheep
committed
custom html added
1 parent 8080df9 commit ccf30cf

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

config/mail-tracker.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22
return [
3-
'track-open'=>true,
4-
'track-click'=> true,
5-
'expire-days'=>60,
6-
'emails-per-page'=>30,
3+
'track-open' => true,
4+
'track-click' => true,
5+
'expire-days' => 60,
6+
'emails-per-page' => 30,
77
'date-format' => 'm/d/Y g:i a',
88
'route' => [
99
'prefix' => 'mail-track',
1010
'middleware' => ['web'],
1111
],
12+
'custom-inject' => false,
13+
'custom-inject-html' => ''
1214
];

src/MailTracker.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ protected function addTrackers($html, $hash)
5454
if(config('mail-tracker.track-click')) {
5555
$html = $this->injectLinkTracker($html, $hash);
5656
}
57-
57+
if (config('mail-tracker.custom-inject')){
58+
$customInject = config('mail-tracker.custom-inject-html');
59+
$html = $this->customInject($html, $customInject);
60+
}
5861
return $html;
5962
}
6063

6164
protected function injectTrackingPixel($html, $hash)
6265
{
6366
// Append the tracking url
64-
$tracking_pixel = '<img src="'.route('mailTracker_t',[$hash]).'" />';
67+
$tracking_pixel = '<img src="'.route('mailTracker_t',[$hash]).'" style="height: 0px; display: inherit;"/>';
6568

6669
$linebreak = str_random(32);
6770
$html = str_replace("\n",$linebreak,$html);
@@ -76,6 +79,20 @@ protected function injectTrackingPixel($html, $hash)
7679
return $html;
7780
}
7881

82+
protected function customInject($html, $injectHtml){
83+
// Append the custom html
84+
$linebreak = str_random(32);
85+
$html = str_replace("\n",$linebreak,$html);
86+
87+
if(preg_match("/^(.*<body[^>]*>)(.*)$/", $html, $matches)) {
88+
$html = $matches[1].$injectHtml.$matches[2];
89+
} else {
90+
$html = $html . $injectHtml;
91+
}
92+
$html = str_replace($linebreak,"\n",$html);
93+
return $html;
94+
}
95+
7996
protected function injectLinkTracker($html, $hash)
8097
{
8198
$this->hash = $hash;

0 commit comments

Comments
 (0)