1. Go to this page and download the library: Download oriceon/mail-tracker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oriceon / mail-tracker example snippets
// In AppServiceProvider
public function boot()
{
MailTracker::ignoreMigrations();
}
\Mail::send('email.test', [], function ($message) {
// ... other settings here
$message->getHeaders()->addTextHeader('X-No-Track', Str::random(10));
});
use Illuminate\Database\Eloquent\Model;
use OriceOn\MailTracker\Concerns\IsSentEmailModel;
use OriceOn\MailTracker\Contracts\SentEmailModel;
class OwnEmailSentModel extends Model implements SentEmailModel {
use IsSentEmailModel;
protected static $unguarded = true;
protected $casts = [
'meta' => 'collection',
'opened_at' => 'datetime',
'clicked_at' => 'datetime',
];
}
public function headers()
{
return [
'X-No-Track' => Str::random(10),
];
}
class ValidUserListener {
public function handle(ValidActionEvent $event)
{
if (in_array(request()->userAgent(), ['Mozilla/5.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246 Mozilla/5.0']) {
$event->skip = true;
}
}
}
namespace App\Listeners;
use OriceOn\MailTracker\Events\ViewEmailEvent;
class EmailViewed
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ViewEmailEvent $event
* @return void
*/
public function handle(ViewEmailEvent $event)
{
// Access the model using $event->sent_email
// Access the IP address that triggered the event using $event->ip_address
}
}
namespace App\Listeners;
use OriceOn\MailTracker\Events\PermanentBouncedMessageEvent;
class BouncedEmail
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param PermanentBouncedMessageEvent $event
* @return void
*/
public function handle(PermanentBouncedMessageEvent $event)
{
// Access the email address using $event->email_address
}
}
/**
* Send an email and do processing on a model with the email
*/
\Mail::send('email.test', [], function ($message) use($email, $subject, $name, $model) {
$message->from('[email protected]', 'From Name');
$message->sender('[email protected]', 'Sender Name');
$message->to($email, $name);
$message->subject($subject);
// Create a custom header that we can later retrieve
$message->getHeaders()->addTextHeader('X-Model-ID',$model->id);
});