Final Class Yiisoft\Mailer\Message
| Inheritance | Yiisoft\Mailer\Message |
|---|---|
| Implements | Yiisoft\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 Yiisoft\Mailer\MailerInterface.
Public Methods
Method Details
| public __construct( string|null $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|null $subject = null, DateTimeImmutable|null $date = null, \Yiisoft\Mailer\Priority|null $priority = null, string|null $returnPath = null, string|null $sender = null, string|null $textBody = null, string|null $htmlBody = null, Yiisoft\Mailer\File[]|null $attachments = null, Yiisoft\Mailer\File[]|null $embeddings = null, array[]|null $headers = null ): mixed | ||
| $charset | string|null | |
| $from | string|string[]|null |
The sender email address(es). You may also specify sender name in addition
to email address using format: |
| $to | string|string[]|null |
The receiver email address(es). You may also specify sender name in addition
to email address using format: |
| $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: |
| $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: |
| $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: |
| $subject | string|null | |
| $date | DateTimeImmutable|null | |
| $priority | \Yiisoft\Mailer\Priority|null | |
| $returnPath | string|null | |
| $sender | string|null | |
| $textBody | string|null | |
| $htmlBody | string|null | |
| $attachments | Yiisoft\Mailer\File[]|null |
The attached files. |
| $embeddings | Yiisoft\Mailer\File[]|null |
The embedded files. |
| $headers | array[]|null |
The custom headers in format: |
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);
}
| public __toString( ): string |
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);
}
| public getAttachments( ): array|null |
public function getAttachments(): ?array
{
return $this->attachments;
}
| public getBcc( ): array|string|null |
public function getBcc(): array|string|null
{
return $this->bcc;
}
| public getDate( ): DateTimeImmutable|null |
public function getDate(): ?DateTimeImmutable
{
return $this->date;
}
| public getEmbeddings( ): array|null |
public function getEmbeddings(): ?array
{
return $this->embeddings;
}
| public getFrom( ): array|string|null |
public function getFrom(): array|string|null
{
return $this->from;
}
| public getHeader( string $name ): array | ||
| $name | string | |
public function getHeader(string $name): array
{
return $this->headers[$name] ?? [];
}
| public getHtmlBody( ): string|null |
public function getHtmlBody(): ?string
{
return $this->htmlBody;
}
| public getPriority( ): \Yiisoft\Mailer\Priority|null |
public function getPriority(): ?Priority
{
return $this->priority;
}
| public getReplyTo( ): array|string|null |
public function getReplyTo(): array|string|null
{
return $this->replyTo;
}
| public getReturnPath( ): string|null |
public function getReturnPath(): ?string
{
return $this->returnPath;
}
| public getTextBody( ): string|null |
public function getTextBody(): ?string
{
return $this->textBody;
}
| public withAddedAttachments( Yiisoft\Mailer\File $files ): Yiisoft\Mailer\Message | ||
| $files | Yiisoft\Mailer\File | |
public function withAddedAttachments(File ...$files): static
{
$new = clone $this;
$new->attachments = array_merge($this->attachments ?? [], $files);
return $new;
}
| public withAddedBcc( array|string $bcc ): Yiisoft\Mailer\Message | ||
| $bcc | array|string | |
public function withAddedBcc(array|string $bcc): static
{
return $this->withBcc(
$this->mergeAddresses($this->bcc, $bcc),
);
}
| public withAddedCc( array|string $cc ): Yiisoft\Mailer\Message | ||
| $cc | array|string | |
public function withAddedCc(array|string $cc): static
{
return $this->withCc(
$this->mergeAddresses($this->cc, $cc),
);
}
| public withAddedEmbeddings( Yiisoft\Mailer\File $files ): Yiisoft\Mailer\Message | ||
| $files | Yiisoft\Mailer\File | |
public function withAddedEmbeddings(File ...$files): static
{
$new = clone $this;
$new->embeddings = array_merge($this->embeddings ?? [], $files);
return $new;
}
| public withAddedFrom( array|string $from ): Yiisoft\Mailer\Message | ||
| $from | array|string | |
public function withAddedFrom(array|string $from): static
{
return $this->withFrom(
$this->mergeAddresses($this->from, $from),
);
}
| public withAddedHeader( string $name, string $value ): Yiisoft\Mailer\Message | ||
| $name | string | |
| $value | string | |
public function withAddedHeader(string $name, string $value): static
{
$new = clone $this;
$new->headers ??= [];
$new->headers[$name][] = $value;
return $new;
}
| public withAddedReplyTo( array|string $replyTo ): Yiisoft\Mailer\Message | ||
| $replyTo | array|string | |
public function withAddedReplyTo(array|string $replyTo): static
{
return $this->withReplyTo(
$this->mergeAddresses($this->replyTo, $replyTo),
);
}
| public withAddedTo( array|string $to ): Yiisoft\Mailer\Message | ||
| $to | array|string | |
public function withAddedTo(array|string $to): static
{
return $this->withTo(
$this->mergeAddresses($this->to, $to),
);
}
| public withAttachments( Yiisoft\Mailer\File $files ): Yiisoft\Mailer\Message | ||
| $files | Yiisoft\Mailer\File | |
public function withAttachments(File ...$files): static
{
$new = clone $this;
$new->attachments = $files;
return $new;
}
| public withBcc( array|string|null $bcc ): Yiisoft\Mailer\Message | ||
| $bcc | array|string|null | |
public function withBcc(array|string|null $bcc): static
{
$new = clone $this;
$new->bcc = $bcc;
return $new;
}
| public withCc( array|string|null $cc ): Yiisoft\Mailer\Message | ||
| $cc | array|string|null | |
public function withCc(array|string|null $cc): static
{
$new = clone $this;
$new->cc = $cc;
return $new;
}
| public withCharset( string|null $charset ): Yiisoft\Mailer\Message | ||
| $charset | string|null | |
public function withCharset(?string $charset): static
{
$new = clone $this;
$new->charset = $charset;
return $new;
}
| public withDate( DateTimeInterface|null $date ): Yiisoft\Mailer\Message | ||
| $date | DateTimeInterface|null | |
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;
}
| public withEmbeddings( Yiisoft\Mailer\File $files ): Yiisoft\Mailer\Message | ||
| $files | Yiisoft\Mailer\File | |
public function withEmbeddings(File ...$files): static
{
$new = clone $this;
$new->embeddings = $files;
return $new;
}
| public withFrom( array|string|null $from ): Yiisoft\Mailer\Message | ||
| $from | array|string|null | |
public function withFrom(array|string|null $from): static
{
$new = clone $this;
$new->from = $from;
return $new;
}
| public withHeader( string $name, array|string $value ): Yiisoft\Mailer\Message | ||
| $name | string | |
| $value | array|string | |
public function withHeader(string $name, array|string $value): static
{
$new = clone $this;
$new->headers[$name] = (array) $value;
return $new;
}
| public withHeaders( array|null $headers ): Yiisoft\Mailer\Message | ||
| $headers | array|null | |
public function withHeaders(?array $headers): static
{
$new = clone $this;
$new->setHeaders($headers);
return $new;
}
| public withHtmlBody( string|null $html ): Yiisoft\Mailer\Message | ||
| $html | string|null | |
public function withHtmlBody(?string $html): static
{
$new = clone $this;
$new->htmlBody = $html;
return $new;
}
| public withPriority( \Yiisoft\Mailer\Priority|null $priority ): Yiisoft\Mailer\Message | ||
| $priority | \Yiisoft\Mailer\Priority|null | |
public function withPriority(?Priority $priority): static
{
$new = clone $this;
$new->priority = $priority;
return $new;
}
| public withReplyTo( array|string|null $replyTo ): Yiisoft\Mailer\Message | ||
| $replyTo | array|string|null | |
public function withReplyTo(array|string|null $replyTo): static
{
$new = clone $this;
$new->replyTo = $replyTo;
return $new;
}
| public withReturnPath( string|null $address ): Yiisoft\Mailer\Message | ||
| $address | string|null | |
public function withReturnPath(?string $address): static
{
$new = clone $this;
$new->returnPath = $address;
return $new;
}
| public withSender( string|null $address ): Yiisoft\Mailer\Message | ||
| $address | string|null | |
public function withSender(?string $address): static
{
$new = clone $this;
$new->sender = $address;
return $new;
}
| public withSubject( string|null $subject ): Yiisoft\Mailer\Message | ||
| $subject | string|null | |
public function withSubject(?string $subject): static
{
$new = clone $this;
$new->subject = $subject;
return $new;
}
| public withTextBody( string|null $text ): Yiisoft\Mailer\Message | ||
| $text | string|null | |
public function withTextBody(?string $text): static
{
$new = clone $this;
$new->textBody = $text;
return $new;
}
| public withTo( array|string|null $to ): Yiisoft\Mailer\Message | ||
| $to | array|string|null | |
public function withTo(array|string|null $to): static
{
$new = clone $this;
$new->to = $to;
return $new;
}
| public withoutAttachments( ): Yiisoft\Mailer\Message |
public function withoutAttachments(): static
{
$new = clone $this;
$new->attachments = null;
return $new;
}
| public withoutEmbeddings( ): Yiisoft\Mailer\Message |
public function withoutEmbeddings(): static
{
$new = clone $this;
$new->embeddings = null;
return $new;
}
Signup or Login in order to comment.