PHP code example of tomazahlin / symfony-mailer-bundle

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

    

tomazahlin / symfony-mailer-bundle example snippets

 php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Ahlin\Bundle\MailerBundle\AhlinMailerBundle(),
    );
}
 php
namespace Company\App;

use Ahlin\Mailer\MailingInterface;

class MyService
{
    private $mailing;
        
    public function __construct(MailingInterface $mailing)
    {
        $this->mailing = $mailing;
    }

    public function doSomething()
    {
        // How to access factory to create mail instances
        $factory = $this->mailing->getFactory();
        
        // How to access mailer to send or queue the mail
        $mailer = $this->mailing->getMailer();
    }
}
 php
namespace Company\Bundle\UserBundle\Mapping;

use Ahlin\Mailer\Mapping\TemplateMappingInterface;

class UserMapping implements TemplateMappingInterface
{
    public function getMappings()
    {
        return array(
            'registration'      => array('view' => 'CompanyUserBundle:Mail:registration.html.twig',     'contentType' => 'text/html'),
            'activation'        => array('view' => 'CompanyUserBundle:Mail:activation.html.twig',       'contentType' => 'text/html'),
            'forgot_password'   => array('view' => 'CompanyUserBundle:Mail:forgot_password.html.twig',  'contentType' => 'text/html'),
        );
    }
}