PHP code example of globegroup / mailer-bundle

1. Go to this page and download the library: Download globegroup/mailer-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

globegroup / mailer-bundle example snippets


    
    
    namespace App\Mailer;
    
    use GlobeGroup\MailerBundle\Mailer\Mailer;
    
    class TestMailer extends Mailer
    {
    
    }
    

    public function sendMessage(User $user): void
    {
        $this->setVariables([
            'user' => $user,
        ]);

        $email = $this->getTemplatedEmail()
            ->subject($this->getTranslatedSubject('authorization.subject'))
            ->htmlTemplate('emails/authorization.html.twig')
            ->addTo($user->getEmail())
            ->context($this->getVariables())
        ;

        $this->mailer->send($email);
    }
    

    
    
    namespace App\Mailer;
    
    use GlobeGroup\MailerBundle\Mailer\Mailer;
    use GlobeGroup\MailerBundle\Mailer\MailerParameters;
    use Symfony\Component\Mailer\MailerInterface;
    use Symfony\Contracts\Translation\TranslatorInterface;
    
    class AuthorizationMailer extends Mailer
    {
        /** @var string $link */
        private $link;
    
        public function __construct(
            MailerInterface $mailer,
            MailerParameters $mailerParameters,
            TranslatorInterface $translator,
            string $link
        ) {
            parent::__construct($mailer, $mailerParameters, $translator);
    
            $this->link = $link;
        }
    }