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 {@see MailerInterface}.
Public Methods
Method Details
| public mixed __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 ) | ||
| $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|null $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|null $subject = null,
private DateTimeImmutable|null $date = null,
private Priority|null $priority = null,
private string|null $returnPath = null,
private string|null $sender = null,
private string|null $textBody = null,
private string|null $htmlBody = null,
private array|null $attachments = null,
private array|null $embeddings = null,
array|null $headers = null,
) {
$this->setHeaders($headers);
}
| 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);
}
| public array|null getAttachments ( ) |
public function getAttachments(): array|null
{
return $this->attachments;
}
| public array|string|null getBcc ( ) |
public function getBcc(): array|string|null
{
return $this->bcc;
}
| public string|null getCharset ( ) |
public function getCharset(): string|null
{
return $this->charset;
}
| public DateTimeImmutable|null getDate ( ) |
public function getDate(): DateTimeImmutable|null
{
return $this->date;
}
| public array|null getEmbeddings ( ) |
public function getEmbeddings(): array|null
{
return $this->embeddings;
}
| public array|string|null getFrom ( ) |
public function getFrom(): array|string|null
{
return $this->from;
}
| public array getHeader ( string $name ) | ||
| $name | string | |
public function getHeader(string $name): array
{
return $this->headers[$name] ?? [];
}
| public array|null getHeaders ( ) |
public function getHeaders(): array|null
{
return $this->headers;
}
| public string|null getHtmlBody ( ) |
public function getHtmlBody(): string|null
{
return $this->htmlBody;
}
| public \Yiisoft\Mailer\Priority|null getPriority ( ) |
public function getPriority(): Priority|null
{
return $this->priority;
}
| public array|string|null getReplyTo ( ) |
public function getReplyTo(): array|string|null
{
return $this->replyTo;
}
| public string|null getReturnPath ( ) |
public function getReturnPath(): string|null
{
return $this->returnPath;
}
| public string|null getSubject ( ) |
public function getSubject(): string|null
{
return $this->subject;
}
| public string|null getTextBody ( ) |
public function getTextBody(): string|null
{
return $this->textBody;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withAddedBcc ( array|string $bcc ) | ||
| $bcc | array|string | |
public function withAddedBcc(array|string $bcc): static
{
return $this->withBcc(
$this->mergeAddresses($this->bcc, $bcc)
);
}
| public Yiisoft\Mailer\Message withAddedCc ( array|string $cc ) | ||
| $cc | array|string | |
public function withAddedCc(array|string $cc): static
{
return $this->withCc(
$this->mergeAddresses($this->cc, $cc)
);
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withAddedFrom ( array|string $from ) | ||
| $from | array|string | |
public function withAddedFrom(array|string $from): static
{
return $this->withFrom(
$this->mergeAddresses($this->from, $from)
);
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withAddedReplyTo ( array|string $replyTo ) | ||
| $replyTo | array|string | |
public function withAddedReplyTo(array|string $replyTo): static
{
return $this->withReplyTo(
$this->mergeAddresses($this->replyTo, $replyTo)
);
}
| public Yiisoft\Mailer\Message withAddedTo ( array|string $to ) | ||
| $to | array|string | |
public function withAddedTo(array|string $to): static
{
return $this->withTo(
$this->mergeAddresses($this->to, $to)
);
}
| public Yiisoft\Mailer\Message withAttachments ( Yiisoft\Mailer\File $files ) | ||
| $files | Yiisoft\Mailer\File | |
public function withAttachments(File ...$files): static
{
$new = clone $this;
$new->attachments = $files;
return $new;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withCharset ( string|null $charset ) | ||
| $charset | string|null | |
public function withCharset(string|null $charset): static
{
$new = clone $this;
$new->charset = $charset;
return $new;
}
| public Yiisoft\Mailer\Message withDate ( DateTimeInterface|null $date ) | ||
| $date | DateTimeInterface|null | |
public function withDate(DateTimeInterface|null $date): static
{
$new = clone $this;
if ($date === null) {
$new->date = $date;
} else {
$new->date = $date instanceof DateTimeImmutable ? $date : DateTimeImmutable::createFromInterface($date);
}
return $new;
}
| public Yiisoft\Mailer\Message withEmbeddings ( Yiisoft\Mailer\File $files ) | ||
| $files | Yiisoft\Mailer\File | |
public function withEmbeddings(File ...$files): static
{
$new = clone $this;
$new->embeddings = $files;
return $new;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withHeaders ( array|null $headers ) | ||
| $headers | array|null | |
public function withHeaders(array|null $headers): static
{
$new = clone $this;
$new->setHeaders($headers);
return $new;
}
| public Yiisoft\Mailer\Message withHtmlBody ( string|null $html ) | ||
| $html | string|null | |
public function withHtmlBody(string|null $html): static
{
$new = clone $this;
$new->htmlBody = $html;
return $new;
}
| public Yiisoft\Mailer\Message withPriority ( \Yiisoft\Mailer\Priority|null $priority ) | ||
| $priority | \Yiisoft\Mailer\Priority|null | |
public function withPriority(Priority|null $priority): static
{
$new = clone $this;
$new->priority = $priority;
return $new;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withReturnPath ( string|null $address ) | ||
| $address | string|null | |
public function withReturnPath(string|null $address): static
{
$new = clone $this;
$new->returnPath = $address;
return $new;
}
| public Yiisoft\Mailer\Message withSender ( string|null $address ) | ||
| $address | string|null | |
public function withSender(string|null $address): static
{
$new = clone $this;
$new->sender = $address;
return $new;
}
| public Yiisoft\Mailer\Message withSubject ( string|null $subject ) | ||
| $subject | string|null | |
public function withSubject(string|null $subject): static
{
$new = clone $this;
$new->subject = $subject;
return $new;
}
| public Yiisoft\Mailer\Message withTextBody ( string|null $text ) | ||
| $text | string|null | |
public function withTextBody(string|null $text): static
{
$new = clone $this;
$new->textBody = $text;
return $new;
}
| public Yiisoft\Mailer\Message 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;
}
| public Yiisoft\Mailer\Message withoutAttachments ( ) |
public function withoutAttachments(): static
{
$new = clone $this;
$new->attachments = null;
return $new;
}
| public Yiisoft\Mailer\Message withoutEmbeddings ( ) |
public function withoutEmbeddings(): static
{
$new = clone $this;
$new->embeddings = null;
return $new;
}
Signup or Login in order to comment.