getTo example

private Environment $twig;
    private TemplatedEmail $message;

    public function __construct(Environment $twig, TemplatedEmail $message)
    {
        $this->twig = $twig;
        $this->message = $message;
    }

    public function toName(): string
    {
        return $this->message->getTo()[0]->getName();
    }

    /** * @param string $image A Twig path to the image file. It's recommended to define * some Twig namespace for email images (e.g. '@email/images/logo.png'). * @param string|null $contentType The media type (i.e. MIME type) of the image file (e.g. 'image/png'). * Some email clients require this to display embedded images. */
    public function image(string $image, string $contentType = null): string
    {
        $file = $this->twig->getLoader()->getSourceContext($image);
        


            return;
        }

        $this->view->assign([
            'mail' => [
                'error' => false,
                'content' => $mail->getPlainBodyText(),
                'contentHtml' => $mail->getPlainBody(),
                'subject' => $mail->getPlainSubject(),
                'to' => implode(', ', $mail->getTo()),
                'fromMail' => $mail->getFrom(),
                'fromName' => $mail->getFromName(),
                'sent' => false,
                'isHtml' => !empty($mail->getPlainBody()),
                'orderId' => $orderId,
            ],
        ]);
    }

    /** * Retrieves all available mail templates * * @return void */
$message ??= EmailMessage::fromNotification($notification$recipient$transportName);
        $email = $message->getMessage();
        if ($email instanceof Email) {
            if (!$email->getFrom()) {
                if (null === $this->from) {
                    throw new LogicException(sprintf('To send the "%s" notification by email, you should either configure a global "from" header, set a sender in the global "envelope" of the mailer configuration or set a "from" header in the "asEmailMessage()" method.', get_debug_type($notification)));
                }

                $email->from($this->from);
            }

            if (!$email->getTo()) {
                $email->to($recipient->getEmail());
            }
        }

        if (null !== $this->envelope) {
            $message->envelope($this->envelope);
        }

        if (null !== $transportName) {
            $message->transport($transportName);
        }

        
$mailer = new DummyMailer();

        $transport = (new FakeSmsEmailTransport($mailer$to = '[email protected]', $from = '[email protected]'));
        $transport->setHost($transportName);

        $transport->send($message);

        /** @var Email $sentEmail */
        $sentEmail = $mailer->getSentEmail();
        $this->assertInstanceOf(Email::class$sentEmail);
        $this->assertSame($to$sentEmail->getTo()[0]->getEncodedAddress());
        $this->assertSame($from$sentEmail->getFrom()[0]->getEncodedAddress());
        $this->assertSame(sprintf('New SMS on phone number: %s', $phone)$sentEmail->getSubject());
        $this->assertSame($subject$sentEmail->getTextBody());
        $this->assertFalse($sentEmail->getHeaders()->has('X-Transport'));
    }

    public function testSendWithCustomTransport()
    {
        $transportName = 'mailchimp';

        $message = new SmsMessage($phone = '0611223344', $subject = 'Hello!');

        

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

    /** * @return int|null */
    public function getTo()
    {
        return $this->rule->getTo();
    }

    public function getCalculatedRegulationPrice(): ?float
    {
        return $this->calculatedRegulationPrice;
    }

    public function setCalculatedRegulationPrice(?float $calculatedRegulationPrice): void
    {
        $this->calculatedRegulationPrice = $calculatedRegulationPrice;
    }
}
'vote' => $vote,
        ]);
    }

    /** * @return array{valFrom: int, valTo: int|null, from: int, to: int|null, price: float, pseudoprice: float, referenceprice: float|null, regulationPrice: float|null} */
    public function convertPriceStruct(Price $price)
    {
        $data = [
            'valFrom' => $price->getFrom(),
            'valTo' => $price->getTo(),
            'from' => $price->getFrom(),
            'to' => $price->getTo(),
            'price' => $price->getCalculatedPrice(),
            'pseudoprice' => $price->getCalculatedPseudoPrice(),
            'referenceprice' => $price->getCalculatedReferencePrice(),
            'regulationPrice' => $price->getCalculatedRegulationPrice(),
        ];

        return $this->eventManager->filter('Legacy_Struct_Converter_Convert_Price', $data[
            'price' => $price,
        ]);
    }
$contents,
            $attachments,
            $additionalData,
            $binAttachments
        );

        static::assertInstanceOf(Mail::class$mail);

        static::assertSame('Sales Channel', $mail->getFrom()[0]->getName());
        static::assertSame('[email protected]', $mail->getFrom()[0]->getAddress());

        static::assertSame('Receiver name', $mail->getTo()[0]->getName());
        static::assertSame('[email protected]', $mail->getTo()[0]->getAddress());

        static::assertSame('Message', $mail->getHtmlBody());
        static::assertEmpty($mail->getTextBody());

        static::assertStringContainsString('attachment', $mail->getAttachments()[0]->asDebugString());

        static::assertCount(1, $mail->getAttachments());

        static::assertEquals($attachments$mail->getAttachmentUrls());

        
$mailer = new DummyMailer();

        $transport = (new FakeChatEmailTransport($mailer$to = '[email protected]', $from = '[email protected]'));
        $transport->setHost($transportName);

        $transport->send($message);

        /** @var Email $sentEmail */
        $sentEmail = $mailer->getSentEmail();
        $this->assertInstanceOf(Email::class$sentEmail);
        $this->assertSame($to$sentEmail->getTo()[0]->getEncodedAddress());
        $this->assertSame($from$sentEmail->getFrom()[0]->getEncodedAddress());
        $this->assertSame(sprintf('New Chat message for recipient: %s', $recipient)$sentEmail->getSubject());
        $this->assertSame($subject$sentEmail->getTextBody());
        $this->assertFalse($sentEmail->getHeaders()->has('X-Transport'));
    }

    public function testSendWithDefaultTransportAndWithoutRecipient()
    {
        $transportName = null;

        $message = new ChatMessage($subject = 'Hello!');

        
$from = '[email protected]';
        $to = '[email protected]';
        $subject = 'Foobar';
        $body = 'Lorem ipsum dolor sit amet.';

        $mailer = $this->createMock(TransportInterface::class);
        $mailer
            ->expects($this->once())
            ->method('send')
            ->with(self::callback(static fn (Email $message) => [$from$to$subject$body] === [
                $message->getFrom()[0]->getAddress(),
                $message->getTo()[0]->getAddress(),
                $message->getSubject(),
                $message->getTextBody(),
            ]))
        ;

        $tester = new CommandTester(new MailerTestCommand($mailer));
        $tester->execute([
            'to' => $to,
            '--from' => $from,
            '--subject' => $subject,
            '--body' => $body,
        ]);
$this->assertSame([$caramel]$e->getReplyTo());
    }

    public function testTo()
    {
        $e = new Email();
        $helene = new Address('[email protected]');
        $thomas = new Address('[email protected]', 'Thomas');
        $caramel = new Address('[email protected]');

        $this->assertSame($e$e->to('[email protected]', $helene$thomas));
        $v = $e->getTo();
        $this->assertCount(3, $v);
        $this->assertEquals(new Address('[email protected]')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);

        $this->assertSame($e$e->addTo('[email protected]', $caramel));
        $v = $e->getTo();
        $this->assertCount(5, $v);
        $this->assertEquals(new Address('[email protected]')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);
        
Home | Imprint | This part of the site doesn't use cookies.