0 follower

Final Class Yiisoft\Mailer\Message

InheritanceYiisoft\Mailer\Message
ImplementsYiisoft\Mailer\MessageInterface

Mail message class that represents the settings and content of an email, such as the sender, recipient, subject, body, etc. Messages are sent by a {@see MailerInterface}.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Mailer\Message
__toString() Yiisoft\Mailer\Message
getAttachments() Yiisoft\Mailer\Message
getBcc() Yiisoft\Mailer\Message
getCc() Yiisoft\Mailer\Message
getCharset() Yiisoft\Mailer\Message
getDate() Yiisoft\Mailer\Message
getEmbeddings() Yiisoft\Mailer\Message
getFrom() Yiisoft\Mailer\Message
getHeader() Yiisoft\Mailer\Message
getHeaders() Yiisoft\Mailer\Message
getHtmlBody() Yiisoft\Mailer\Message
getPriority() Yiisoft\Mailer\Message
getReplyTo() Yiisoft\Mailer\Message
getReturnPath() Yiisoft\Mailer\Message
getSender() Yiisoft\Mailer\Message
getSubject() Yiisoft\Mailer\Message
getTextBody() Yiisoft\Mailer\Message
getTo() Yiisoft\Mailer\Message
withAddedAttachments() Yiisoft\Mailer\Message
withAddedBcc() Yiisoft\Mailer\Message
withAddedCc() Yiisoft\Mailer\Message
withAddedEmbeddings() Yiisoft\Mailer\Message
withAddedFrom() Yiisoft\Mailer\Message
withAddedHeader() Yiisoft\Mailer\Message
withAddedReplyTo() Yiisoft\Mailer\Message
withAddedTo() Yiisoft\Mailer\Message
withAttachments() Yiisoft\Mailer\Message
withBcc() Yiisoft\Mailer\Message
withCc() Yiisoft\Mailer\Message
withCharset() Yiisoft\Mailer\Message
withDate() Yiisoft\Mailer\Message
withEmbeddings() Yiisoft\Mailer\Message
withFrom() Yiisoft\Mailer\Message
withHeader() Yiisoft\Mailer\Message
withHeaders() Yiisoft\Mailer\Message
withHtmlBody() Yiisoft\Mailer\Message
withPriority() Yiisoft\Mailer\Message
withReplyTo() Yiisoft\Mailer\Message
withReturnPath() Yiisoft\Mailer\Message
withSender() Yiisoft\Mailer\Message
withSubject() Yiisoft\Mailer\Message
withTextBody() Yiisoft\Mailer\Message
withTo() Yiisoft\Mailer\Message
withoutAttachments() Yiisoft\Mailer\Message
withoutEmbeddings() Yiisoft\Mailer\Message

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( ?string $charset null, string|string[]|null $from null, string|string[]|null $to null, string|string[]|null $replyTo null, string|string[]|null $cc null, string|string[]|null $bcc null, ?string $subject null, ?\DateTimeImmutable $date null, ?\Yiisoft\Mailer\Priority $priority null, ?string $returnPath null, ?string $sender null, ?string $textBody null, ?string $htmlBody null, Yiisoft\Mailer\File[]|null $attachments null, Yiisoft\Mailer\File[]|null $embeddings null, array[]|null $headers null )
$charset ?string
$from string|string[]|null

The sender email address(es). You may also specify sender name in addition to email address using format: [email => name].

$to string|string[]|null

The receiver email address(es). You may also specify sender name in addition to email address using format: [email => name].

$replyTo string|string[]|null

The reply-to address(es) of this message. You may also specify sender name in addition to email address using format: [email => name].

$cc string|string[]|null

The additional copy receiver address(es) of this message. You may also specify sender name in addition to email address using format: [email => name].

$bcc string|string[]|null

The hidden copy receiver address(es) of this message. You may also specify sender name in addition to email address using format: [email => name].

$subject ?string
$date ?\DateTimeImmutable
$priority ?\Yiisoft\Mailer\Priority
$returnPath ?string
$sender ?string
$textBody ?string
$htmlBody ?string
$attachments Yiisoft\Mailer\File[]|null

The attached files.

$embeddings Yiisoft\Mailer\File[]|null

The embedded files.

$headers array[]|null

The custom headers in format: [name => value|value[]].

                public function __construct(
    private ?string $charset = null,
    private array|string|null $from = null,
    private array|string|null $to = null,
    private array|string|null $replyTo = null,
    private array|string|null $cc = null,
    private array|string|null $bcc = null,
    private ?string $subject = null,
    private ?DateTimeImmutable $date = null,
    private ?Priority $priority = null,
    private ?string $returnPath = null,
    private ?string $sender = null,
    private ?string $textBody = null,
    private ?string $htmlBody = null,
    private ?array $attachments = null,
    private ?array $embeddings = null,
    ?array $headers = null,
) {
    $this->setHeaders($headers);
}

            
__toString() public method

public string __toString ( )

                public function __toString(): string
{
    $result = [];
    if ($this->headers !== null) {
        foreach ($this->headers as $name => $values) {
            foreach ($values as $value) {
                $result[] = $name . ': ' . $value;
            }
        }
    }
    $result[] = $this->textBody;
    return implode("\n", $result);
}

            
getAttachments() public method

public ?array getAttachments ( )

                public function getAttachments(): ?array
{
    return $this->attachments;
}

            
getBcc() public method

public array|string|null getBcc ( )

                public function getBcc(): array|string|null
{
    return $this->bcc;
}

            
getCc() public method

public array|string|null getCc ( )

                public function getCc(): array|string|null
{
    return $this->cc;
}

            
getCharset() public method

public ?string getCharset ( )

                public function getCharset(): ?string
{
    return $this->charset;
}

            
getDate() public method

public ?\DateTimeImmutable getDate ( )

                public function getDate(): ?DateTimeImmutable
{
    return $this->date;
}

            
getEmbeddings() public method

public ?array getEmbeddings ( )

                public function getEmbeddings(): ?array
{
    return $this->embeddings;
}

            
getFrom() public method

public array|string|null getFrom ( )

                public function getFrom(): array|string|null
{
    return $this->from;
}

            
getHeader() public method

public array getHeader ( string $name )
$name string

                public function getHeader(string $name): array
{
    return $this->headers[$name] ?? [];
}

            
getHeaders() public method

public ?array getHeaders ( )

                public function getHeaders(): ?array
{
    return $this->headers;
}

            
getHtmlBody() public method

public ?string getHtmlBody ( )

                public function getHtmlBody(): ?string
{
    return $this->htmlBody;
}

            
getPriority() public method

public ?\Yiisoft\Mailer\Priority getPriority ( )

                public function getPriority(): ?Priority
{
    return $this->priority;
}

            
getReplyTo() public method

public array|string|null getReplyTo ( )

                public function getReplyTo(): array|string|null
{
    return $this->replyTo;
}

            
getReturnPath() public method

public ?string getReturnPath ( )

                public function getReturnPath(): ?string
{
    return $this->returnPath;
}

            
getSender() public method

public ?string getSender ( )

                public function getSender(): ?string
{
    return $this->sender;
}

            
getSubject() public method

public ?string getSubject ( )

                public function getSubject(): ?string
{
    return $this->subject;
}

            
getTextBody() public method

public ?string getTextBody ( )

                public function getTextBody(): ?string
{
    return $this->textBody;
}

            
getTo() public method

public array|string|null getTo ( )

                public function getTo(): array|string|null
{
    return $this->to;
}

            
withAddedAttachments() public method

public static withAddedAttachments ( Yiisoft\Mailer\File $files )
$files Yiisoft\Mailer\File

                public function withAddedAttachments(File ...$files): static
{
    $new = clone $this;
    $new->attachments = array_merge($this->attachments ?? [], $files);
    return $new;
}

            
withAddedBcc() public method

public static withAddedBcc ( array|string $bcc )
$bcc array|string

                public function withAddedBcc(array|string $bcc): static
{
    return $this->withBcc(
        $this->mergeAddresses($this->bcc, $bcc),
    );
}

            
withAddedCc() public method

public static withAddedCc ( array|string $cc )
$cc array|string

                public function withAddedCc(array|string $cc): static
{
    return $this->withCc(
        $this->mergeAddresses($this->cc, $cc),
    );
}

            
withAddedEmbeddings() public method

public static withAddedEmbeddings ( Yiisoft\Mailer\File $files )
$files Yiisoft\Mailer\File

                public function withAddedEmbeddings(File ...$files): static
{
    $new = clone $this;
    $new->embeddings = array_merge($this->embeddings ?? [], $files);
    return $new;
}

            
withAddedFrom() public method

public static withAddedFrom ( array|string $from )
$from array|string

                public function withAddedFrom(array|string $from): static
{
    return $this->withFrom(
        $this->mergeAddresses($this->from, $from),
    );
}

            
withAddedHeader() public method

public static withAddedHeader ( string $name, string $value )
$name string
$value string

                public function withAddedHeader(string $name, string $value): static
{
    $new = clone $this;
    $new->headers ??= [];
    $new->headers[$name][] = $value;
    return $new;
}

            
withAddedReplyTo() public method

public static withAddedReplyTo ( array|string $replyTo )
$replyTo array|string

                public function withAddedReplyTo(array|string $replyTo): static
{
    return $this->withReplyTo(
        $this->mergeAddresses($this->replyTo, $replyTo),
    );
}

            
withAddedTo() public method

public static withAddedTo ( array|string $to )
$to array|string

                public function withAddedTo(array|string $to): static
{
    return $this->withTo(
        $this->mergeAddresses($this->to, $to),
    );
}

            
withAttachments() public method

public static withAttachments ( Yiisoft\Mailer\File $files )
$files Yiisoft\Mailer\File

                public function withAttachments(File ...$files): static
{
    $new = clone $this;
    $new->attachments = $files;
    return $new;
}

            
withBcc() public method

public static withBcc ( array|string|null $bcc )
$bcc array|string|null

                public function withBcc(array|string|null $bcc): static
{
    $new = clone $this;
    $new->bcc = $bcc;
    return $new;
}

            
withCc() public method

public static withCc ( array|string|null $cc )
$cc array|string|null

                public function withCc(array|string|null $cc): static
{
    $new = clone $this;
    $new->cc = $cc;
    return $new;
}

            
withCharset() public method

public static withCharset ( ?string $charset )
$charset ?string

                public function withCharset(?string $charset): static
{
    $new = clone $this;
    $new->charset = $charset;
    return $new;
}

            
withDate() public method

public static withDate ( ?\DateTimeInterface $date )
$date ?\DateTimeInterface

                public function withDate(?DateTimeInterface $date): static
{
    $new = clone $this;
    if ($date === null) {
        $new->date = $date;
    } else {
        $new->date = $date instanceof DateTimeImmutable ? $date : DateTimeImmutable::createFromInterface($date);
    }
    return $new;
}

            
withEmbeddings() public method

public static withEmbeddings ( Yiisoft\Mailer\File $files )
$files Yiisoft\Mailer\File

                public function withEmbeddings(File ...$files): static
{
    $new = clone $this;
    $new->embeddings = $files;
    return $new;
}

            
withFrom() public method

public static withFrom ( array|string|null $from )
$from array|string|null

                public function withFrom(array|string|null $from): static
{
    $new = clone $this;
    $new->from = $from;
    return $new;
}

            
withHeader() public method

public static withHeader ( string $name, array|string $value )
$name string
$value array|string

                public function withHeader(string $name, array|string $value): static
{
    $new = clone $this;
    $new->headers[$name] = (array) $value;
    return $new;
}

            
withHeaders() public method

public static withHeaders ( ?array $headers )
$headers ?array

                public function withHeaders(?array $headers): static
{
    $new = clone $this;
    $new->setHeaders($headers);
    return $new;
}

            
withHtmlBody() public method

public static withHtmlBody ( ?string $html )
$html ?string

                public function withHtmlBody(?string $html): static
{
    $new = clone $this;
    $new->htmlBody = $html;
    return $new;
}

            
withPriority() public method

public static withPriority ( ?\Yiisoft\Mailer\Priority $priority )
$priority ?\Yiisoft\Mailer\Priority

                public function withPriority(?Priority $priority): static
{
    $new = clone $this;
    $new->priority = $priority;
    return $new;
}

            
withReplyTo() public method

public static withReplyTo ( array|string|null $replyTo )
$replyTo array|string|null

                public function withReplyTo(array|string|null $replyTo): static
{
    $new = clone $this;
    $new->replyTo = $replyTo;
    return $new;
}

            
withReturnPath() public method

public static withReturnPath ( ?string $address )
$address ?string

                public function withReturnPath(?string $address): static
{
    $new = clone $this;
    $new->returnPath = $address;
    return $new;
}

            
withSender() public method

public static withSender ( ?string $address )
$address ?string

                public function withSender(?string $address): static
{
    $new = clone $this;
    $new->sender = $address;
    return $new;
}

            
withSubject() public method

public static withSubject ( ?string $subject )
$subject ?string

                public function withSubject(?string $subject): static
{
    $new = clone $this;
    $new->subject = $subject;
    return $new;
}

            
withTextBody() public method

public static withTextBody ( ?string $text )
$text ?string

                public function withTextBody(?string $text): static
{
    $new = clone $this;
    $new->textBody = $text;
    return $new;
}

            
withTo() public method

public static withTo ( array|string|null $to )
$to array|string|null

                public function withTo(array|string|null $to): static
{
    $new = clone $this;
    $new->to = $to;
    return $new;
}

            
withoutAttachments() public method

public static withoutAttachments ( )

                public function withoutAttachments(): static
{
    $new = clone $this;
    $new->attachments = null;
    return $new;
}

            
withoutEmbeddings() public method

public static withoutEmbeddings ( )

                public function withoutEmbeddings(): static
{
    $new = clone $this;
    $new->embeddings = null;
    return $new;
}