addCc example

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>')
            ->addPart(new DataPart(file_get_contents(__FILE__), 'foobar.php'))
        );
$binAttachment['fileName'],
                    $binAttachment['mimeType']
                );
            }
        }

        foreach ($additionalData as $key => $value) {
            switch ($key) {
                case 'recipientsCc':
                    $mailAddresses = \is_array($value) ? $value : [$value => $value];
                    $this->assertValidAddresses(array_keys($mailAddresses));
                    $mail->addCc(...$this->formatMailAddresses($mailAddresses));

                    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));
                    
'http_code' => 202,
                'response_headers' => ['x-message-id' => 'test_message_id'],
            ]);
        });

        $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()
    {


        $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());
    }
}
$helene = new Address('helene@symfony.com');
        $thomas = new Address('thomas@symfony.com', 'Thomas');
        $caramel = new Address('caramel@symfony.com');

        $this->assertSame($e$e->cc('fabien@symfony.com', $helene$thomas));
        $v = $e->getCc();
        $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->addCc('lucas@symfony.com', $caramel));
        $v = $e->getCc();
        $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->addCc('lucas@symfony.com', $caramel);
        $this->assertCount(2, $e->getCc());

        
if ( count( $matches ) === 3 ) {
                            $recipient_name = $matches[1];
                            $address        = $matches[2];
                        }
                    }

                    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;
                }
            }

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

    /** * @return $this */
    public function addCc(string $address, string $name = '')static
    {
        $this->message->addCc(new Address($address$name));

        return $this;
    }

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

    


        $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());
    }
}
Home | Imprint | This part of the site doesn't use cookies.