PHP code example of diego-mascarenhas / emailer

1. Go to this page and download the library: Download diego-mascarenhas/emailer 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/ */

    

diego-mascarenhas / emailer example snippets


return [
    'email_provider' => env('EMAILER_PROVIDER', 'smtp'),
    'queue_name' => env('EMAILER_QUEUE', 'emailer'),
    'delays' => [
        'base_minutes' => env('EMAILER_DELAY_BASE_MINUTES', 5),
        'random_seconds' => env('EMAILER_DELAY_RANDOM_SECONDS', 120),
    ],
    // ... more configuration options
];

use idoneo\Emailer\Models\Message;
use idoneo\Emailer\Models\MessageType;
use idoneo\Emailer\Facades\Emailer;

// Create a message type
$messageType = MessageType::create([
    'name' => 'Newsletter',
    'status' => 1
]);

// Create a message
$message = Message::create([
    'name' => 'Welcome Newsletter',
    'subject' => 'Welcome to our platform!',
    'content' => '<h1>Welcome {{name}}!</h1><p>Thank you for joining us.</p>',
    'type_id' => $messageType->id,
    'team_id' => auth()->user()->currentTeam->id,
    'status_id' => 1
]);

// Start the campaign
Emailer::startCampaign($message);

// Send a test email
Emailer::sendTest($message, '[email protected]', 'Test User');

$stats = Emailer::getCampaignStats($message);

echo "Total sent: " . $stats['sent'];
echo "Open rate: " . $stats['open_rate'] . "%";
echo "Click rate: " . $stats['click_rate'] . "%";

// In your Team model, implement these methods:
public function hasOutgoingEmailConfig(): bool
{
    return $this->getSetting('mail_host') !== null;
}

public function getOutgoingEmailConfig(): array
{
    return [
        'host' => $this->getSetting('mail_host'),
        'port' => $this->getSetting('mail_port', 587),
        'username' => $this->getSetting('mail_username'),
        'password' => $this->getSetting('mail_password'),
        'encryption' => $this->getSetting('mail_encryption', 'tls'),
        'from_address' => $this->getSetting('mail_from_address'),
        'from_name' => $this->getSetting('mail_from_name'),
    ];
}

// In your SendMessageCampaignJob extension
protected function sendViaCustomProvider()
{
    // Implement your custom provider logic
}

$message = Message::create([
    'content' => '<h1>Hello {{name}}!</h1><p>Your email is {{email}}</p>',
    // ...
]);

// Your Team model should have:
public function messages()
{
    return $this->hasMany(\idoneo\Emailer\Models\Message::class);
}

// Your Contact model should have:  
public function messageDeliveries()
{
    return $this->hasMany(\idoneo\Emailer\Models\MessageDelivery::class);
}

// Your Category model should have:
public function messages()
{
    return $this->hasMany(\idoneo\Emailer\Models\Message::class);
}
bash
php artisan vendor:publish --tag="emailer-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="emailer-config"
bash
php artisan queue:work --queue=emailer