Skip to content

Mailer

Methods

withHtml

Sets message type to HTML or plaintext.

public withHtml(bool $isHtml = false): static

Parameters:

Parameter Type Description
$isHtml bool True for HTML mode.

withAttachment

Add an attachment from a path on the filesystem.

public withAttachment(string $path, string $name = '', string $encode = PHPMailer::ENCODING_BASE64, string $type = '', string $disposition = 'attachment'): static

Parameters:

Parameter Type Description
$path string Path to the attachment
$name string Overrides the attachment name
$encode string File encoding (see $Encoding)
$type string MIME type, e.g. image/jpeg; determined automatically from $path if not specified
$disposition string Disposition to use.

Throws:


withBody

Set Mail Body configuration

public withBody(array|string $data, array $options = []): static

Format email message Body, this can be an external template html file with a copy of a plain-text like template.txt or HTML/plain-text string.

This method can be used by passing a template file HTML name and an associative array with the values that can be parsed into the file HTML by the key KEY_NAME found in your array to your HTML {{KEY_NAME}}.

Other optional ways to format the mail body is available like instead of a template the param $data can be set as an array or string, but param $options['template_name'] must be equal to null.

Parameters:

Parameter Type Description
$data array|string Contain the values to be parsed in mail body.
$options array Array of options.

withAltBody

The plain-text message body.

public withAltBody(string $message = ''): static

Parameters:

Parameter Type Description
$message string

save

Save message as eml file.

public save(): bool

Return Value:

True if saved successfully, false otherwise.

Throws:


send

Create a message and send it.

public send(): bool

Uses the sending method specified by $Mailer.

Return Value:

false on error.

Throws:


Inherited methods

withSmtp

Send messages using SMTP.

public withSmtp(): static

Throws:


withMail

Send messages using PHP's native mail() function.

public withMail(): static

withSendmail

Send messages using Sendmail.

public withSendmail(): static

withQmail

Send messages using qmail.

public withQmail(): static

withFrom

Set the From and FromName properties.

public withFrom(string $address, string $name = '', bool $auto = true): static

Parameters:

Parameter Type Description
$address string
$name string
$auto bool Whether to also set the Sender address, defaults to true.

Throws:


withTo

Add a "To" address.

public withTo(string|array $address): static

Parameters:

Parameter Type Description
$address string|array The email address(es) to send to.

Throws:


withCc

Add a "CC" address.

public withCc(string|array $address): static

Parameters:

Parameter Type Description
$address string|array The email address(es) to send to.

Throws:


withBcc

Add a "BCC" address.

public withBcc(string|array $address): static

Parameters:

Parameter Type Description
$address string|array The email address(es) to send to.

Throws:


withReplyTo

Add a "Reply-To" address.

public withReplyTo(string|array $address): static

Parameters:

Parameter Type Description
$address string|array The email address(es) to reply to.

Throws:


withSender

The envelope sender of the message.

public withSender(string $sender = ''): static

This will usually be turned into a Return-Path header by the receiver, and is the address that bounces will be sent to.

Parameters:

Parameter Type Description
$sender string

withSubject

The Subject of the message.

public withSubject(string $subject = ''): static

Parameters:

Parameter Type Description
$subject string

withPriority

Email priority.

public withPriority(int|null $priority = null): static

Options: null (default), 1 = High, 3 = Normal, 5 = low. When null, the header is not set at all.

Parameters:

Parameter Type Description
$priority int|null

withCharset

The character set of the message.

public withCharset(string $charset = PHPMailer::CHARSET_ISO88591): static

Parameters:

Parameter Type Description
$charset string The character set of the message.

withCustomHeader

Add a custom header.

public withCustomHeader(string $name, string|null $value = null): static

$name value can be overloaded to contain both header name and value (name:value).

Parameters:

Parameter Type Description
$name string Custom header name.
$value string|null Header value.

Throws:


withContentType

The MIME Content-type of the message.

public withContentType(string $contentType = PHPMailer::CONTENT_TYPE_PLAINTEXT): static

Parameters:

Parameter Type Description
$contentType string

withXMailer

What to put in the X-Mailer header.

public withXMailer(string|null $xmailer = ''): static

Options: An empty string for PHPMailer default, whitespace/null for none, or a string to use.

Parameters:

Parameter Type Description
$xmailer string|null


Automatically generated on 2025-10-13