0 follower

Final Class Yiisoft\Mailer\SwiftMailer\Message

InheritanceYiisoft\Mailer\SwiftMailer\Message
ImplementsYiisoft\Mailer\MessageInterface

Message implements a message class based on SwiftMailer.

See also:

Public Methods

Hide inherited methods

Method Description Defined By
__clone() Yiisoft\Mailer\SwiftMailer\Message
__construct() Yiisoft\Mailer\SwiftMailer\Message
__toString() Yiisoft\Mailer\SwiftMailer\Message
getBcc() Yiisoft\Mailer\SwiftMailer\Message
getCc() Yiisoft\Mailer\SwiftMailer\Message
getCharset() Yiisoft\Mailer\SwiftMailer\Message
getDate() Yiisoft\Mailer\SwiftMailer\Message
getError() Yiisoft\Mailer\SwiftMailer\Message
getFrom() Yiisoft\Mailer\SwiftMailer\Message
getHeader() Yiisoft\Mailer\SwiftMailer\Message
getHtmlBody() Yiisoft\Mailer\SwiftMailer\Message
getPriority() Yiisoft\Mailer\SwiftMailer\Message
getReadReceiptTo() Returns the addresses to which a read-receipt will be sent. Yiisoft\Mailer\SwiftMailer\Message
getReplyTo() Yiisoft\Mailer\SwiftMailer\Message
getReturnPath() Yiisoft\Mailer\SwiftMailer\Message
getSender() Yiisoft\Mailer\SwiftMailer\Message
getSubject() Yiisoft\Mailer\SwiftMailer\Message
getSwiftMessage() Returns a Swift message instance. Yiisoft\Mailer\SwiftMailer\Message
getTextBody() Yiisoft\Mailer\SwiftMailer\Message
getTo() Yiisoft\Mailer\SwiftMailer\Message
withAddedHeader() Yiisoft\Mailer\SwiftMailer\Message
withAttached() Yiisoft\Mailer\SwiftMailer\Message
withAttachedSigners() Returns a new instance with the specified attached signers. Yiisoft\Mailer\SwiftMailer\Message
withBcc() Yiisoft\Mailer\SwiftMailer\Message
withCc() Yiisoft\Mailer\SwiftMailer\Message
withCharset() Yiisoft\Mailer\SwiftMailer\Message
withDate() Yiisoft\Mailer\SwiftMailer\Message
withEmbedded() Yiisoft\Mailer\SwiftMailer\Message
withError() Yiisoft\Mailer\SwiftMailer\Message
withFrom() Yiisoft\Mailer\SwiftMailer\Message
withHeader() Yiisoft\Mailer\SwiftMailer\Message
withHeaders() Yiisoft\Mailer\SwiftMailer\Message
withHtmlBody() Yiisoft\Mailer\SwiftMailer\Message
withPriority() Yiisoft\Mailer\SwiftMailer\Message
withReadReceiptTo() Returns a new instance with the specified ask for a delivery receipt from the recipient to be sent to addresses. Yiisoft\Mailer\SwiftMailer\Message
withReplyTo() Yiisoft\Mailer\SwiftMailer\Message
withReturnPath() Yiisoft\Mailer\SwiftMailer\Message
withSender() Yiisoft\Mailer\SwiftMailer\Message
withSubject() Yiisoft\Mailer\SwiftMailer\Message
withTextBody() Yiisoft\Mailer\SwiftMailer\Message
withTo() Yiisoft\Mailer\SwiftMailer\Message

Method Details

Hide inherited methods

__clone() public method

public __clone( ): mixed

                public function __clone()
{
    $this->swiftMessage = clone $this->swiftMessage;
}

            
__construct() public method

public __construct( ): mixed

                public function __construct()
{
    $this->swiftMessage = new Swift_Message();
}

            
__toString() public method

public __toString( ): string

                public function __toString(): string
{
    return $this->swiftMessage->toString();
}

            
getBcc() public method

public getBcc( ): mixed

                public function getBcc()
{
    return $this->normalizeAddresses($this->swiftMessage->getBcc());
}

            
getCc() public method

public getCc( ): mixed

                public function getCc()
{
    return $this->normalizeAddresses($this->swiftMessage->getCc());
}

            
getCharset() public method

public getCharset( ): string

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

            
getDate() public method

public getDate( ): DateTimeImmutable|null

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

            
getError() public method

public getError( ): Throwable|null

                public function getError(): ?Throwable
{
    return $this->error;
}

            
getFrom() public method

public getFrom( ): mixed

                public function getFrom()
{
    return $this->normalizeAddresses($this->swiftMessage->getFrom());
}

            
getHeader() public method

public getHeader( string $name ): array
$name string

                public function getHeader(string $name): array
{
    $headerSet = $this->swiftMessage->getHeaders();
    if (!$headerSet->has($name)) {
        return [];
    }
    $headers = [];
    /** @var Swift_Mime_Headers_UnstructuredHeader $header */
    foreach ($headerSet->getAll($name) as $header) {
        $headers[] = $header->getValue();
    }
    return $headers;
}

            
getHtmlBody() public method

public getHtmlBody( ): string

                public function getHtmlBody(): string
{
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return (string) $this->swiftMessage->getBody();
}

            
getPriority() public method

public getPriority( ): integer

                public function getPriority(): int
{
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return (int) $this->swiftMessage->getPriority();
}

            
getReadReceiptTo() public method

Returns the addresses to which a read-receipt will be sent.

public getReadReceiptTo( ): array<string, string>|string
return array<string, string>|string

The receipt receive email addresses.

                public function getReadReceiptTo()
{
    return $this->normalizeAddresses($this->swiftMessage->getReadReceiptTo());
}

            
getReplyTo() public method

public getReplyTo( ): mixed

                public function getReplyTo()
{
    return $this->normalizeAddresses($this->swiftMessage->getReplyTo());
}

            
getReturnPath() public method

public getReturnPath( ): string

                public function getReturnPath(): string
{
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return (string) $this->swiftMessage->getReturnPath();
}

            
getSender() public method

public getSender( ): string

                public function getSender(): string
{
    /** @var array<string, null>|null $sender */
    $sender = $this->swiftMessage->getSender();
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return empty($sender) ? '' : (string) array_key_first($sender);
}

            
getSubject() public method

public getSubject( ): string

                public function getSubject(): string
{
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return (string) $this->swiftMessage->getSubject();
}

            
getSwiftMessage() public method

Returns a Swift message instance.

public getSwiftMessage( ): \Swift_Message
return \Swift_Message

Swift message instance.

                public function getSwiftMessage(): Swift_Message
{
    return $this->swiftMessage;
}

            
getTextBody() public method

public getTextBody( ): string

                public function getTextBody(): string
{
    /** @psalm-suppress RedundantCastGivenDocblockType */
    return (string) $this->swiftMessage->getBody();
}

            
getTo() public method

public getTo( ): mixed

                public function getTo()
{
    return $this->normalizeAddresses($this->swiftMessage->getTo());
}

            
withAddedHeader() public method

public withAddedHeader( string $name, string $value ): self
$name string
$value string

                public function withAddedHeader(string $name, string $value): self
{
    $new = clone $this;
    $new->swiftMessage
        ->getHeaders()
        ->addTextHeader($name, $value);
    return $new;
}

            
withAttached() public method

public withAttached( \Yiisoft\Mailer\File $file ): self
$file \Yiisoft\Mailer\File

                public function withAttached(File $file): self
{
    $attachment = $file->path() === null
        ? new Swift_Attachment($file->content())
        : Swift_Attachment::fromPath($file->path())
    ;
    if (!empty($file->name())) {
        $attachment->setFilename($file->name());
    }
    if (!empty($file->contentType())) {
        $attachment->setContentType($file->contentType());
    }
    $new = clone $this;
    $new->swiftMessage->attach($attachment);
    return $new;
}

            
withAttachedSigners() public method

Returns a new instance with the specified attached signers.

public withAttachedSigners( \Swift_Signer[] $signers ): self
$signers \Swift_Signer[]

                public function withAttachedSigners(array $signers): self
{
    $new = clone $this;
    foreach ($signers as $signer) {
        $new->swiftMessage->attachSigner($signer);
    }
    return $new;
}

            
withBcc() public method

public withBcc( mixed $bcc ): self
$bcc mixed

                public function withBcc($bcc): self
{
    $new = clone $this;
    $new->swiftMessage->setBcc($bcc);
    return $new;
}

            
withCc() public method

public withCc( mixed $cc ): self
$cc mixed

                public function withCc($cc): self
{
    $new = clone $this;
    $new->swiftMessage->setCc($cc);
    return $new;
}

            
withCharset() public method

public withCharset( string $charset ): self
$charset string

                public function withCharset(string $charset): self
{
    $new = clone $this;
    $new->swiftMessage->setCharset($charset);
    return $new;
}

            
withDate() public method

public withDate( DateTimeInterface $date ): self
$date DateTimeInterface

                public function withDate(DateTimeInterface $date): self
{
    if ($date instanceof DateTime) {
        $immutable = new DateTimeImmutable('@' . $date->getTimestamp());
        $date = $immutable->setTimezone($date->getTimezone());
    }
    $new = $this->withHeader('Date', $date->format(DateTimeInterface::RFC2822));
    $new->date = $date;
    return $new;
}

            
withEmbedded() public method

public withEmbedded( \Yiisoft\Mailer\File $file ): self
$file \Yiisoft\Mailer\File

                public function withEmbedded(File $file): self
{
    $embedFile = $file->path() === null
        ? new Swift_EmbeddedFile($file->content())
        : Swift_EmbeddedFile::fromPath($file->path())
    ;
    if (!empty($file->name())) {
        $embedFile->setFilename($file->name());
    }
    if (!empty($file->contentType())) {
        $embedFile->setContentType($file->contentType());
    }
    $new = clone $this;
    $new->swiftMessage->embed($embedFile->setId($file->id()));
    return $new;
}

            
withError() public method

public withError( Throwable $e ): self
$e Throwable

                public function withError(Throwable $e): self
{
    $new = clone $this;
    $new->error = $e;
    return $new;
}

            
withFrom() public method

public withFrom( mixed $from ): self
$from mixed

                public function withFrom($from): self
{
    $new = clone $this;
    $new->swiftMessage->setFrom($from);
    return $new;
}

            
withHeader() public method

public withHeader( string $name, mixed $value ): self
$name string
$value mixed

                public function withHeader(string $name, $value): self
{
    $new = clone $this;
    $headerSet = $new->swiftMessage->getHeaders();
    if ($headerSet->has($name)) {
        $headerSet->remove($name);
    }
    foreach ((array) $value as $v) {
        $headerSet->addTextHeader($name, $v);
    }
    return $new;
}

            
withHeaders() public method

public withHeaders( array $headers ): self
$headers array

                public function withHeaders(array $headers): self
{
    $new = clone $this;
    foreach ($headers as $name => $value) {
        $new = $new->withHeader($name, $value);
    }
    return $new;
}

            
withHtmlBody() public method

public withHtmlBody( string $html ): self
$html string

                public function withHtmlBody(string $html): self
{
    $new = clone $this;
    $new->setBody($html, 'text/html');
    return $new;
}

            
withPriority() public method

public withPriority( integer $priority ): self
$priority integer

                public function withPriority(int $priority): self
{
    $new = clone $this;
    $new->swiftMessage->setPriority($priority);
    return $new;
}

            
withReadReceiptTo() public method

Returns a new instance with the specified ask for a delivery receipt from the recipient to be sent to addresses.

public withReadReceiptTo( string|string[] $addresses ): self
$addresses string|string[]

The receipt receive email address(es).

                public function withReadReceiptTo($addresses): self
{
    $new = clone $this;
    $new->swiftMessage->setReadReceiptTo((array) $addresses);
    return $new;
}

            
withReplyTo() public method

public withReplyTo( mixed $replyTo ): self
$replyTo mixed

                public function withReplyTo($replyTo): self
{
    $new = clone $this;
    $new->swiftMessage->setReplyTo($replyTo);
    return $new;
}

            
withReturnPath() public method

public withReturnPath( string $address ): self
$address string

                public function withReturnPath(string $address): self
{
    $new = clone $this;
    $new->swiftMessage->setReturnPath($address);
    return $new;
}

            
withSender() public method

public withSender( string $address ): self
$address string

                public function withSender(string $address): self
{
    $new = clone $this;
    $new->swiftMessage->setSender($address);
    return $new;
}

            
withSubject() public method

public withSubject( string $subject ): self
$subject string

                public function withSubject(string $subject): self
{
    $new = clone $this;
    $new->swiftMessage->setSubject($subject);
    return $new;
}

            
withTextBody() public method

public withTextBody( string $text ): self
$text string

                public function withTextBody(string $text): self
{
    $new = clone $this;
    $new->setBody($text, 'text/plain');
    return $new;
}

            
withTo() public method

public withTo( mixed $to ): self
$to mixed

                public function withTo($to): self
{
    $new = clone $this;
    $new->swiftMessage->setTo($to);
    return $new;
}