DLight\Application\Mail
Mô tả: SMTP mailer (TLS/SSL), hỗ trợ To/CC/BCC, attachment, và render body từ View.
Config đọc từ .env hoặc config/mail.php.
Namespace / đăng ký
- Namespace:
DLight\Application - File:
src/Application/Mail.php
Public API (fluent)
__construct(?array $config = null)to(string $email): selfcc(string $email): selfbcc(string $email): selfsubject(string $subject): selfbody(string $body): selfhtml(string $html): selftext(string $text): selfview(string $viewName, ?array $data = null): selfaddAttachment(string $filePath, ?string $fileName = null): selfsend(): bool
Demo gửi mail
use DLight\Application\Mail;
(new Mail())
->to('user@example.com')
->subject('Welcome')
->text("Xin chào!\nChúc bạn một ngày tốt lành.")
->send();
Demo gửi mail bằng view + attachment
use DLight\Application\Mail;
(new Mail())
->to('user@example.com')
->subject('Invoice')
->view('mail.invoice', ['order' => $order])
->addAttachment(INDEX_DIR . 'files/invoice.pdf', 'invoice.pdf')
->send();
Env liên quan
- MAIL_SERVICE: preset (gmail/outlook/yahoo/zoho/mailgun/sendgrid/ses...)
- MAIL_HOST, MAIL_PORT, MAIL_ENCRYPTION (tls/ssl), MAIL_AUTH
- MAIL_USERNAME, MAIL_PASSWORD
- MAIL_FROM_ADDRESS, MAIL_FROM_NAME
- MAIL_TIMEOUT, MAIL_EHLO_DOMAIN