API Reference
Mailable
Namespace: WPZylos\Framework\Mail\Mailable
Fluent email builder that constructs and sends emails via wp_mail().
Recipients
to(string|array $address): static
Add one or more recipients. Can be called multiple times to accumulate addresses.
$mail->to('[email protected]');
$mail->to(['[email protected]', '[email protected]']);
cc(string|array $address): static
Add CC recipients. Added as Cc: headers.
bcc(string|array $address): static
Add BCC recipients. Added as Bcc: headers.
replyTo(string $address): static
Set the reply-to address. Added as Reply-To: header.
from(string $address, string $name = ''): static
Set the from address and optional display name. Added as From: header.
Content
subject(string $subject): static
Set the email subject line.
html(string $html): static
Set raw HTML as the email body. Highest priority — overrides text, view, and component body.
text(string $text): static
Set plain text as the email body. Used when no html() is set.
view(string $template, array $data = []): static
Set a PHP template file to render as the body. Template receives $data as extracted variables.
$template— Template name (without.phpextension)$data— Associative array of variables to pass to the template
line(string $text): static
Add a line of text to the component-based body. Rendered as <p> tags inside the HTML layout.
greeting(string $greeting): static
Set a greeting line. Rendered as <h2> at the top of the component body.
action(string $text, string $url): static
Add a call-to-action button. Rendered as a styled link button.
$text— Button label$url— Button URL
Attachments & Headers
attach(string $path): static
Add a file attachment by absolute path.
header(string $key, string $value): static
Add a custom email header.
Configuration
templatePath(string $path): static
Set the base directory for view template files. Templates are resolved as {path}/{template}.php.
Execution
build(): array
Build the email into its wp_mail() components without sending.
Returns:
[
'to' => string[], // Recipient addresses
'subject' => string, // Subject line
'message' => string, // Rendered body
'headers' => string[], // Header strings
'attachments' => string[], // File paths
]
send(): bool
Build and send the email via wp_mail(). Returns true on success.
Accessors
getSubject(): string
Get the current subject line.
getTo(): array
Get the current recipient list.
MailManager
Namespace: WPZylos\Framework\Mail\MailManager
Central mail service that provides preconfigured Mailable instances.
Constructor
__construct(ContextInterface $context)
$context— WPZylos plugin context, used to resolve the default template path.
Methods
to(string|array $address): Mailable
Create a new Mailable with defaults applied, addressed to the given recipient(s).
$mailManager->to('[email protected]')
->subject('Hello')
->send();
send(Mailable $mailable): bool
Send an existing Mailable instance. Delegates to $mailable->send().
createMailable(): Mailable
Create a new Mailable with defaults applied (from address, template path).
setFrom(string $address, string $name = ''): void
Set the default from address and display name for all future mailables.
getFromAddress(): string
Get the current default from address. Falls back to get_option('admin_email').
getFromName(): string
Get the current default from name. Falls back to get_option('blogname').
MailServiceProvider
Namespace: WPZylos\Framework\Mail\MailServiceProvider
Implements ServiceProviderInterface.
Methods
register(ApplicationInterface $app): void
Registers services in the container:
MailManager::class— singleton'mail'— alias for MailManager
boot(ApplicationInterface $app): void
No-op. No boot actions needed.