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): self
  • cc(string $email): self
  • bcc(string $email): self
  • subject(string $subject): self
  • body(string $body): self
  • html(string $html): self
  • text(string $text): self
  • view(string $viewName, ?array $data = null): self
  • addAttachment(string $filePath, ?string $fileName = null): self
  • send(): 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