PHP code example of schvoy / mail-template-bundle

1. Go to this page and download the library: Download schvoy/mail-template-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/ */

    

schvoy / mail-template-bundle example snippets




declare(strict_types=1);

namespace App\Mails;

use Schvoy\MailTemplateBundle\Mailer\AbstractMailType;
use Schvoy\MailTemplateBundle\Mailer\Engine\TwigBased;

class TestMailType extends AbstractMailType
{
    use TwigBased;

    protected string $subject = 'first_email.test.subject'; // Translation key

    protected string $body = 'first_email.test.body'; // Translation key
}

$testMail = $mailSender->getMailType(TestMailType::class);

$mailSender->send(
    $testMail,
    [
        new Recipient('[email protected]', 'Test user'),
        new Recipient('[email protected]'),
    ],
    [
        'parameters' => [
            '%test%' => 'Test parameter',
        ],
    ]
);

[
    '__greeting' => true,
    '__signature' => true,
    '__userName' => $recipient->getName() ?? false,
    '__mailType' => $mailType,
    '__translationDomain' => $this->parameterBag->get(
        sprintf('%s.%s', MailTemplateBundleExtension::ALIAS, 'translation_domain')
    ),
    '__locale' => 'en',
    'parameters' => [
        '%userName%' => $recipient->getName(),
        '%signatory%' => $this->parameterBag->get('mailer_signatory'),
    ],
]