PHP code example of dinara / email-marketing
1. Go to this page and download the library: Download dinara/email-marketing 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/ */
dinara / email-marketing example snippets
'tenant_resolver' => fn() => auth()->user()?->tenant_id,
'tenant_resolver' => fn() => app('currentTenant')?->id,
use Dinara\EmailMarketing\Models\EmailTemplate;
use Dinara\EmailMarketing\Models\EmailCampaign;
use Dinara\EmailMarketing\Services\EmailCampaignService;
use Dinara\EmailMarketing\Services\SmtpConfigService;
// Create a template
$template = EmailTemplate::create([
'name' => 'Welcome Email',
'subject' => 'Welcome {{contact_name}}!',
'body_html' => '<h1>Hello {{contact_name}}</h1><p>Welcome to our service!</p>',
'is_active' => true,
]);
// Create and start a campaign
$service = app(EmailCampaignService::class);
$campaign = $service->createCampaign(
name: 'Welcome Campaign',
templateId: $template->id,
recipientIds: [1, 2, 3] // Lead IDs
);
$service->startCampaign($campaign);
// For SaaS: Set tenant before operations
$smtpService = app(SmtpConfigService::class);
$smtpService->setTenant($tenantId);
$settings = $smtpService->getSettings();
bash
php artisan migrate
bash
php artisan vendor:publish --tag=email-marketing-config
bash
php artisan vendor:publish --tag=email-marketing-views
bash
php artisan queue:work
bash
php artisan horizon
bash
php artisan vendor:publish --tag=email-marketing-views