Mailing
Třída Moony\bootstrap\core\services\Mail obaluje PHPMailer. SMTP nastavení se bere automaticky z konfigurace (sekce mail).
Základní použití
use Moony\bootstrap\core\services\Mail;
// Textový obsah
Mail::to('user@example.com')->send('Subject', 'Obsah emailu');
// Twig šablona jako obsah
Mail::to('user@example.com')->send('Vítejte', new View('emails/welcome', [
'userName' => 'Denis',
]));
Fluent API
| Mail::to(string $email) | Vytvoří instanci s příjemcem |
| ->setFromEmail(string $email) | Přepíše odesílatele (jinak z configu) |
| ->setFromName(string $name) | Přepíše jméno odesílatele |
| ->setReplyTo(string $email, string $name) | Nastaví Reply-To adresu |
| ->cc(string|array $emails) | Přidá CC příjemce |
| ->bcc(string|array $emails) | Přidá BCC příjemce |
| ->addAttachment(Attachment $attachment) | Přidá přílohu |
| ->addEmbeddedImage(EmbeddedImage $image) | Přidá vloženou ikonu/obrázek (pro HTML email) |
| ->send(string $subject, View|string $content) | Odešle email. Vrátí bool. |
Kompletní příklad
use Moony\bootstrap\core\services\Mail;
use Moony\bootstrap\core\services\mail\Attachment;
use Moony\bootstrap\core\services\mail\EmbeddedImage;
Mail::to('user@example.com')
->setReplyTo('support@example.com', 'Support')
->cc('manager@example.com')
->bcc(['archive@example.com', 'backup@example.com'])
->addAttachment(new Attachment(
ROOT . 'storage/exports/report.pdf',
'Report.pdf'
))
->addEmbeddedImage(new EmbeddedImage(
ROOT . 'assets/img/logo.png',
'company_logo' // použití v HTML: <img src="cid:company_logo">
))
->send('Měsíční report', new View('emails/monthly-report', [
'month' => 'Březen 2026'
]));
Konfigurace
V config/production.php (nebo local.php):
'mail' => [
'from' => [
'email' => 'noreply@example.com',
'name' => 'My App'
],
'smtp' => [
'use' => true,
'hostname' => 'smtp.example.com',
'username' => 'user@example.com',
'password' => 'secret',
'secure' => 'tls',
'port' => 587
]
]
