PHP code example of fullstack / inbounder

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

    

fullstack / inbounder example snippets


use Inbounder\Models\EmailTemplate;

$template = EmailTemplate::create([
    'name' => 'Welcome Email',
    'slug' => 'welcome-email',
    'subject' => 'Welcome to {{company}}!',
    'html_content' => '<h1>Welcome {{name}}!</h1><p>Thank you for joining {{company}}.</p>',
    'text_content' => 'Welcome {{name}}! Thank you for joining {{company}}.',
    'variables' => ['name', 'company'],
    'is_active' => true,
]);

use Inbounder\Services\TemplatedEmailJobDispatcher;

$dispatcher = app(TemplatedEmailJobDispatcher::class);

// Send to one recipient
$dispatcher->sendToOne(
    '[email protected]',
    'welcome-email',
    ['name' => 'John Doe', 'company' => 'Acme Corp']
);

// Send to multiple recipients
$recipients = [
    ['email' => '[email protected]', 'name' => 'John', 'company' => 'Acme'],
    ['email' => '[email protected]', 'name' => 'Jane', 'company' => 'Acme'],
];

$dispatcher->sendToMany($recipients, 'welcome-email');

// Send as a batch
$batch = $dispatcher->sendBatch($recipients, 'welcome-email');

use Inbounder\Models\DistributionList;

$list = DistributionList::create([
    'name' => 'Newsletter Subscribers',
    'slug' => 'newsletter-subscribers',
    'description' => 'Monthly newsletter subscribers',
    'category' => 'newsletter',
    'is_active' => true,
]);

use Inbounder\Services\DistributionListService;

$service = app(DistributionListService::class);

$service->addSubscribers($list->id, [
    ['email' => '[email protected]', 'name' => 'John Doe'],
    ['email' => '[email protected]', 'name' => 'Jane Smith'],
]);

$service->sendCampaign($list->id, 'newsletter-template', [
    'month' => 'January',
    'year' => '2024',
]);

Route::post('/mailgun/webhook', [MailgunController::class, 'webhook'])
    ->middleware('verify.mailgun.webhook');

Route::post('/mailgun/inbound', [MailgunController::class, 'inbound'])
    ->middleware('verify.mailgun.webhook');

'authorization' => [
    'method' => 'gate', // 'gate', 'policy', or 'spatie'
    'gate_name' => 'send-email',
    'policy_method' => 'sendEmail',
    'spatie_permission' => 'send email',
],

// Using Gates
Gate::define('send-email', function ($user) {
    return $user->hasPermission('send-email');
});

// Using Policies
class UserPolicy
{
    public function sendEmail(User $user): bool
    {
        return $user->hasPermission('send-email');
    }
}

// Using Spatie Permissions
$user->givePermissionTo('send email');

use Inbounder\Events\EmailTemplateCreated;
use Inbounder\Events\DistributionListCreated;

Event::listen(EmailTemplateCreated::class, function ($event) {
    Log::info('Email template created', [
        'template_id' => $event->getTemplateId(),
        'template_name' => $event->getTemplateName(),
    ]);
});

Event::listen(DistributionListCreated::class, function ($event) {
    Log::info('Distribution list created', [
        'list_id' => $event->getListId(),
        'list_name' => $event->getListName(),
    ]);
});
bash
php artisan vendor:publish --tag=inbounder-config
bash
# Process templated emails
php artisan queue:work --queue=mailgun-emails

# Process webhook events
php artisan queue:work --queue=mailgun-webhooks

# Process inbound emails
php artisan queue:work --queue=mailgun-inbound

# Process tracking events
php artisan queue:work --queue=mailgun-tracking
bash
# Create a template
php artisan inbounder:templates:create

# List templates
php artisan inbounder:templates:list

# Send a templated email
php artisan inbounder:templates:send