PHP code example of visualbuilder / email-templates
1. Go to this page and download the library: Download visualbuilder/email-templates 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/ */
visualbuilder / email-templates example snippets
'multitenancy' => [
'enabled' => true,
'tenant_model' => App\Models\Team::class,
// Optional - derived automatically from tenant model if not set:
// 'tenant_foreign_key' => 'team_id',
// 'ownership_relationship' => 'team',
],
use Visualbuilder\EmailTemplates\EmailTemplatesPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
EmailTemplatesPlugin::make()
->multitenancy()
->tenantModel(Team::class),
]);
}
// AdminPanelProvider.php
->plugins([
EmailTemplatesPlugin::make()
->screenshotCapture(function (string $html): ?array {
// Example using a screenshot service (Browsershot, Puppeteer Lambda, etc.)
return app(ScreenshotService::class)->htmlToBase64($html, [
'viewport' => 'mobile',
'fullPage' => true,
]);
}),
])
$theme->getFirstMediaUrl('screenshot'); // Original
$theme->getFirstMediaUrl('screenshot', 'thumb'); // Thumbnail
/**
* Allowed config keys which can be inserted into email templates
* eg use ##config.app.name## in the email template for automatic replacement.
*/
'config_keys' => [
'app.name',
'app.url',
'email-templates.customer-services'
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Visualbuilder\EmailTemplates\Traits\BuildGenericEmail;
class MyFunkyNewEmail extends Mailable
{
use Queueable, SerializesModels, BuildGenericEmail;
public string $template = 'email-template-key'; //Change this to the key of the email template content to load
public string $sendTo;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($user) {
$this->sendTo = $user;
}
}
class MyFunkyNewEmail extends Mailable
{
use Queueable, SerializesModels, BuildGenericEmail;
public string $template = 'email-template-key'; //Change this to the key of the email template content to load
public string $sendTo;
public Model $booking;
public function __construct($user, Booking $booking) {
$this->user = $user;
$this->booking = $booking;
$this->sendTo = $user->email;
}
public function getFullNameAttribute()
{
return $this->firstname.' '.$this->lastname;
}
class SalesOrderEmail extends Mailable
{
use Queueable, SerializesModels, BuildGenericEmail;
public string $template = 'email-template-key';
public string $sendTo;
public $attachment;
public User $user;
public Order $order;
public Invoice $invoice;
/**
* Constructor for SalesOrderEmail.
*
* @param User $user User object
* @param Order $order Order object
* @param Invoice $invoice Invoice object
*/
public function __construct($user, $order, $invoice) {
$this->user = $user;
$this->order = $order;
$this->invoice = $invoice;
$this->attachment = $invoice->getPdf(); // Missing semicolon added
$this->sendTo = $user->email;
}
}
class SalesOrderEmail extends Mailable
{
use Queueable, SerializesModels, BuildGenericEmail;
public string $template = 'email-template-key';
public string $sendTo;
public $attachment;
/**
* Constructor for SalesOrderEmail using PHP 8 constructor property promotion.
*
* @param User $user User object
* @param Order $order Order object
* @param Invoice $invoice Invoice object
*/
public function __construct(public User $user, public Order $order, public Invoice $invoice) {
$this->attachment = $invoice->getPdf();
$this->sendTo = $user->email;
}
}