PHP code example of benlehr / mail-campaign-tracker

1. Go to this page and download the library: Download benlehr/mail-campaign-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/ */

    

benlehr / mail-campaign-tracker example snippets


// In AppServiceProvider

public function boot()
{
    MailTracker::ignoreMigrations();
}


use benlehr\mail-tracker\MailCampaignHelper;

// get the helper 
$helper = new MailCampaignHelper();
// create a campaign and get ID
$campaignId = $helper->createCampaign('name of campaign');

// fetch your users
$users = User::all();

foreach ($users as $user) {
    // send mail and inject campaign id
  Mail::to($user->email)->send(new TestMail($campaignId));
}





namespace App\Listeners;

use benlehr\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 benlehr\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
    }
}

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'benlehr\MailTracker\Events\EmailSentEvent' => [
        'App\Listeners\EmailSent',
    ],
    'benlehr\MailTracker\Events\ViewEmailEvent' => [
        'App\Listeners\EmailViewed',
    ],
    'benlehr\MailTracker\Events\LinkClickedEvent' => [
        'App\Listeners\EmailLinkClicked',
    ],
    'benlehr\MailTracker\Events\EmailDeliveredEvent' => [
        'App\Listeners\EmailDelivered',
    ],
    'benlehr\MailTracker\Events\ComplaintMessageEvent' => [
        'App\Listeners\EmailComplaint',
    ],
    'benlehr\MailTracker\Events\PermanentBouncedMessageEvent' => [
        'App\Listeners\BouncedEmail',
    ],
];
bash
$ php artisan vendor:publish --provider="benlehr\MailTracker\MailTrackerServiceProvider"
bash
$ php artisan migrate

php artisan make:trackable-mail 'MailName'