addReplyTo example

break;
                case 'recipientsBcc':
                    $mailAddresses = \is_array($value) ? $value : [$value => $value];
                    $this->assertValidAddresses(array_keys($mailAddresses));
                    $mail->addBcc(...$this->formatMailAddresses($mailAddresses));

                    break;
                case 'replyTo':
                    $mailAddresses = \is_array($value) ? $value : [$value => $value];
                    $this->assertValidAddresses(array_keys($mailAddresses));
                    $mail->addReplyTo(...$this->formatMailAddresses($mailAddresses));

                    break;
                case 'returnPath':
                    $mailAddresses = \is_array($value) ? $value : [$value => $value];
                    $this->assertValidAddresses(array_keys($mailAddresses));
                    $mail->returnPath(...$this->formatMailAddresses($mailAddresses));
            }
        }

        return $mail;
    }

    
$transport = new SendinblueApiTransport('ACCESS_KEY', $client);
        $transport->setPort(8984);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello here!')
            ->html('Hello there!')
            ->addCc('foo@bar.fr')
            ->addBcc('foo@bar.fr')
            ->addReplyTo('foo@bar.fr')
            ->addPart(new DataPart('body'))
        ;

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }
}
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;

class EmailController
{
    public function indexAction(MailerInterface $mailer)
    {
        $mailer->send((new Email())->to('fabien@symfony.com')->from('fabien@symfony.com')->subject('Foo')
            ->addReplyTo('me@symfony.com')
            ->addCc('cc@symfony.com')
            ->text('Bar!')
            ->html('<p>Foo</p>')
            ->addPart(new DataPart(file_get_contents(__FILE__), 'foobar.php'))
        );

        $mailer->send((new Email())->to('fabien@symfony.com', 'thomas@symfony.com')->from('fabien@symfony.com')->subject('Foo')
            ->addReplyTo(new Address('me@symfony.com', 'Fabien Potencier'))
            ->addCc('cc@symfony.com')
            ->text('Bar!')
            ->html('<p>Foo</p>')
            
switch ( $address_header ) {
                        case 'to':
                            $phpmailer->addAddress( $address$recipient_name );
                            break;
                        case 'cc':
                            $phpmailer->addCc( $address$recipient_name );
                            break;
                        case 'bcc':
                            $phpmailer->addBcc( $address$recipient_name );
                            break;
                        case 'reply_to':
                            $phpmailer->addReplyTo( $address$recipient_name );
                            break;
                    }
                } catch ( PHPMailer\PHPMailer\Exception $e ) {
                    continue;
                }
            }
        }

        // Set to use PHP's mail().         $phpmailer->isMail();

        
$helene = new Address('helene@symfony.com');
        $thomas = new Address('thomas@symfony.com', 'Thomas');
        $caramel = new Address('caramel@symfony.com');

        $this->assertSame($e$e->replyTo('fabien@symfony.com', $helene$thomas));
        $v = $e->getReplyTo();
        $this->assertCount(3, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);

        $this->assertSame($e$e->addReplyTo('lucas@symfony.com', $caramel));
        $v = $e->getReplyTo();
        $this->assertCount(5, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);
        $this->assertEquals(new Address('lucas@symfony.com')$v[3]);
        $this->assertSame($caramel$v[4]);

        $e = new Email();
        $e->addReplyTo('lucas@symfony.com', $caramel);
        $this->assertCount(2, $e->getReplyTo());

        
$transport = new BrevoApiTransport('ACCESS_KEY', $client);
        $transport->setPort(8984);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello here!')
            ->html('Hello there!')
            ->addCc('foo@bar.fr')
            ->addBcc('foo@bar.fr')
            ->addReplyTo('foo@bar.fr')
            ->addPart(new DataPart('body'));

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }
}

    public function getFrom(): array
    {
        return $this->message->getFrom();
    }

    /** * @return $this */
    public function addReplyTo(string $address)static
    {
        $this->message->addReplyTo($address);

        return $this;
    }

    /** * @return Address[] */
    public function getReplyTo(): array
    {
        return $this->message->getReplyTo();
    }

    

        });

        $transport = new MailerSendApiTransport('ACCESS_KEY', $client);

        $mail = new Email();
        $mail->subject('Test subject')
            ->to(new Address('test_to@example.com', 'Test to name'))
            ->from(new Address('test_from@example.com', 'Test from name'))
            ->addCc('test_cc@example.com')
            ->addBcc('test_bcc@example.com')
            ->addReplyTo('test_reply_to@example.com')
            ->text('Lorem ipsum.')
            ->html('<html><body><p>Lorem ipsum.</p></body></html>');

        $message = $transport->send($mail);

        $this->assertSame('test_message_id', $message->getMessageId());
    }

    public function testSendEmailWithAttachment()
    {
        $client = new MockHttpClient(function Dstring $method, string $url, array $options): ResponseInterface {
            
Home | Imprint | This part of the site doesn't use cookies.