0 follower

Final Class Yiisoft\Mailer\MessageSettings

InheritanceYiisoft\Mailer\MessageSettings

MessageSettings provides default and extra message settings.

Psalm Types

Name Value
HtmlToTextBodyConverterCallable callable

Public Properties

Hide inherited properties

Property Type Description Defined By
$addAttachments array|null Yiisoft\Mailer\MessageSettings
$addBcc array|string|null Yiisoft\Mailer\MessageSettings
$addCc array|string|null Yiisoft\Mailer\MessageSettings
$addEmbeddings array|null Yiisoft\Mailer\MessageSettings
$addFrom array|string|null Yiisoft\Mailer\MessageSettings
$addReplyTo array|string|null Yiisoft\Mailer\MessageSettings
$addTo array|string|null Yiisoft\Mailer\MessageSettings
$attachments array|null Yiisoft\Mailer\MessageSettings
$bcc array|string|null Yiisoft\Mailer\MessageSettings
$cc array|string|null Yiisoft\Mailer\MessageSettings
$charset string|null Yiisoft\Mailer\MessageSettings
$date DateTimeImmutable|null Yiisoft\Mailer\MessageSettings
$embeddings array|null Yiisoft\Mailer\MessageSettings
$from array|string|null Yiisoft\Mailer\MessageSettings
$headers array[]|null The custom headers in format [name => value[]] that will be added if there are no corresponding headers in the message. Yiisoft\Mailer\MessageSettings
$htmlBody string|null Yiisoft\Mailer\MessageSettings
$htmlToTextBodyConverter callable|null The HTML to text body converter. Yiisoft\Mailer\MessageSettings
$overwriteHeaders array[]|null The custom headers in format [name => value[]] that will always be added to message. Yiisoft\Mailer\MessageSettings
$priority \Yiisoft\Mailer\Priority|null Yiisoft\Mailer\MessageSettings
$replyTo array|string|null Yiisoft\Mailer\MessageSettings
$returnPath string|null Yiisoft\Mailer\MessageSettings
$sender string|null Yiisoft\Mailer\MessageSettings
$subject string|null Yiisoft\Mailer\MessageSettings
$textBody string|null Yiisoft\Mailer\MessageSettings
$to array|string|null Yiisoft\Mailer\MessageSettings

Property Details

Hide inherited properties

$addAttachments public property
public array|null $addAttachments null
$addBcc public property
public array|string|null $addBcc null
$addCc public property
public array|string|null $addCc null
$addEmbeddings public property
public array|null $addEmbeddings null
$addFrom public property
public array|string|null $addFrom null
$addReplyTo public property
public array|string|null $addReplyTo null
$addTo public property
public array|string|null $addTo null
$attachments public property
public array|null $attachments null
$bcc public property
public array|string|null $bcc null
$cc public property
public array|string|null $cc null
$charset public property
public string|null $charset null
$date public property
$embeddings public property
public array|null $embeddings null
$from public property
public array|string|null $from null
$headers public property

The custom headers in format [name => value[]] that will be added if there are no corresponding headers in the message.

public array[]|null $headers null
$htmlBody public property
public string|null $htmlBody null
$htmlToTextBodyConverter public property

The HTML to text body converter.

$overwriteHeaders public property

The custom headers in format [name => value[]] that will always be added to message.

public array[]|null $overwriteHeaders null
$priority public property
public \Yiisoft\Mailer\Priority|null $priority null
$replyTo public property
public array|string|null $replyTo null
$returnPath public property
public string|null $returnPath null
$sender public property
public string|null $sender null
$subject public property
public string|null $subject null
$textBody public property
public string|null $textBody null
$to public property
public array|string|null $to null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|null $charset null, string|string[]|null $from null, string|string[]|null $addFrom null, string|string[]|null $to null, string|string[]|null $addTo null, string|string[]|null $replyTo null, string|string[]|null $addReplyTo null, string|string[]|null $cc null, string|string[]|null $addCc null, string|string[]|null $bcc null, string|string[]|null $addBcc 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 $addAttachments null, Yiisoft\Mailer\File[]|null $embeddings null, Yiisoft\Mailer\File[]|null $addEmbeddings null, array[]|null $headers null, array[]|null $overwriteHeaders null, callable|null $htmlToTextBodyConverter 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: [email => name].

$addFrom string|string[]|null

The sender email address(es) that will always be added to message. 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].

$addTo string|string[]|null

The receiver email address(es) that will always be added to message. 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].

$addReplyTo string|string[]|null

The reply-to address(es) that will always be added to 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].

$addCc string|string[]|null

The additional copy receiver address(es) that will always be added to 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].

$addBcc string|string[]|null

The hidden copy receiver address(es) that will always be added to message. You may also specify sender name in addition to email address using format: [email => name].

$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.

$addAttachments Yiisoft\Mailer\File[]|null

The attached files that will always be added to message.

$embeddings Yiisoft\Mailer\File[]|null

The embedded files.

$addEmbeddings Yiisoft\Mailer\File[]|null

The embedded files that will always be added to message.

$headers array[]|null

The custom headers in format [name => value|value[]] that will be added if there are no corresponding headers in the message.

$overwriteHeaders array[]|null

The custom headers in format [name => value|value[]] that will always be added to message.

$htmlToTextBodyConverter callable|null

The HTML to text body converter.

                public function __construct(
    public readonly string|null $charset = null,
    public readonly array|string|null $from = null,
    public readonly array|string|null $addFrom = null,
    public readonly array|string|null $to = null,
    public readonly array|string|null $addTo = null,
    public readonly array|string|null $replyTo = null,
    public readonly array|string|null $addReplyTo = null,
    public readonly array|string|null $cc = null,
    public readonly array|string|null $addCc = null,
    public readonly array|string|null $bcc = null,
    public readonly array|string|null $addBcc = null,
    public readonly string|null $subject = null,
    public readonly DateTimeImmutable|null $date = null,
    public readonly Priority|null $priority = null,
    public readonly string|null $returnPath = null,
    public readonly string|null $sender = null,
    public readonly string|null $textBody = null,
    public readonly string|null $htmlBody = null,
    public readonly array|null $attachments = null,
    public readonly array|null $addAttachments = null,
    public readonly array|null $embeddings = null,
    public readonly array|null $addEmbeddings = null,
    array|null $headers = null,
    array|null $overwriteHeaders = null,
    callable|null $htmlToTextBodyConverter = null,
) {
    $this->headers = HeadersNormalizer::normalize($headers);
    $this->overwriteHeaders = HeadersNormalizer::normalize($overwriteHeaders);
    $this->htmlToTextBodyConverter = $htmlToTextBodyConverter;
}

            
applyTo() public method

public Yiisoft\Mailer\MessageInterface applyTo ( Yiisoft\Mailer\MessageInterface $message )
$message Yiisoft\Mailer\MessageInterface

                public function applyTo(MessageInterface $message): MessageInterface
{
    if ($this->charset !== null && $message->getCharset() === null) {
        $message = $message->withCharset($this->charset);
    }
    if ($this->from !== null && $message->getFrom() === null) {
        $message = $message->withFrom($this->from);
    }
    if ($this->addFrom !== null) {
        $message = $message->withAddedFrom($this->addFrom);
    }
    if ($this->to !== null && $message->getTo() === null) {
        $message = $message->withTo($this->to);
    }
    if ($this->addTo !== null) {
        $message = $message->withAddedTo($this->addTo);
    }
    if ($this->replyTo !== null && $message->getReplyTo() === null) {
        $message = $message->withReplyTo($this->replyTo);
    }
    if ($this->addReplyTo !== null) {
        $message = $message->withAddedReplyTo($this->addReplyTo);
    }
    if ($this->cc !== null && $message->getCc() === null) {
        $message = $message->withCc($this->cc);
    }
    if ($this->addCc !== null) {
        $message = $message->withAddedCc($this->addCc);
    }
    if ($this->bcc !== null && $message->getBcc() === null) {
        $message = $message->withBcc($this->bcc);
    }
    if ($this->addBcc !== null) {
        $message = $message->withAddedBcc($this->addBcc);
    }
    if ($this->subject !== null && $message->getSubject() === null) {
        $message = $message->withSubject($this->subject);
    }
    if ($this->date !== null && $message->getDate() === null) {
        $message = $message->withDate($this->date);
    }
    if ($this->priority !== null && $message->getPriority() === null) {
        $message = $message->withPriority($this->priority);
    }
    if ($this->returnPath !== null && $message->getReturnPath() === null) {
        $message = $message->withReturnPath($this->returnPath);
    }
    if ($this->sender !== null && $message->getSender() === null) {
        $message = $message->withSender($this->sender);
    }
    if ($this->textBody !== null && $message->getTextBody() === null) {
        $message = $message->withTextBody($this->textBody);
    }
    if ($this->htmlBody !== null && $message->getHtmlBody() === null) {
        $message = $message->withHtmlBody($this->htmlBody);
    }
    if ($this->attachments !== null && $message->getAttachments() === null) {
        $message = $message->withAttachments(...$this->attachments);
    }
    if ($this->addAttachments !== null) {
        $message = $message->withAddedAttachments(...$this->addAttachments);
    }
    if ($this->embeddings !== null && $message->getEmbeddings() === null) {
        $message = $message->withEmbeddings(...$this->embeddings);
    }
    if ($this->addEmbeddings !== null) {
        $message = $message->withAddedEmbeddings(...$this->addEmbeddings);
    }
    if ($this->headers !== null) {
        $message = $message->withHeaders(
            array_merge($this->headers, $message->getHeaders() ?? [])
        );
    }
    if ($this->overwriteHeaders !== null) {
        foreach ($this->overwriteHeaders as $headerName => $headerValue) {
            $message = $message->withHeader($headerName, $headerValue);
        }
    }
    if ($this->htmlToTextBodyConverter !== null && $message->getTextBody() === null) {
        $html = $message->getHtmlBody();
        if ($html !== null) {
            $message = $message->withTextBody(
                ($this->htmlToTextBodyConverter)($html)
            );
        }
    }
    return $message;
}