1. Go to this page and download the library: Download jacquesndl/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/ */
jacquesndl / mailer-bundle example snippets
// src/Controller/WelcomeController.php
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Jacquesndl\MailerBundle\Message\TemplatedEmail;
class WelcomeController extends AbstractController
{
public function index(MailerInterface $mailer): Response
{
// ...
$email = (new TemplatedEmail())
->from('[email protected]') // overwrite the default sender value
->to('[email protected]')
->replyTo('[email protected]')
->template('emails/welcome.email.twig')
->attachFromPath('/path/to/documents/coupe-du-monde-1998.pdf')
->context([
'firstName' => 'Zinédine',
])
;
$mailer->send($email);
// ...
}
}
// src/Email/WelcomeEmail.php
namespace App\Email;
use Jacquesndl\MailerBundle\Message\TemplatedEmail;
class WelcomeEmail extends TemplatedEmail
{
protected $template = 'emails/welcome.email.twig';
}
// src/Controller/WelcomeController.php
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use App\Email\WelcomeEmail;
class WelcomeController extends AbstractController
{
public function index(MailerInterface $mailer): Response
{
// ...
$email = (new WelcomeEmail())
->to('[email protected]');
$mailer->send($email);
// ...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.