1. Go to this page and download the library: Download c975l/email-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/ */
c975l / email-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new c975L\EmailBundle\c975LEmailBundle(),
];
}
}
// src/Controller/AnyController.php
use c975L\EmailBundle\Service\EmailServiceInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class AnyController extends AbstractController
{
public function anyFunction(Request $request, EmailServiceInterface $emailService)
{
// ...
//Build your email
$body = $this->renderView('emails/description.html.twig', array(
//Data needed for your template
));
$emailData = array(
'subject' => 'YOUR_SUBJECT',
'sentFrom' => $emailService->getParameter('c975LEmail.sentFrom'),
'sentTo' => '[email protected]',
'sentCc' => '[email protected]', //optional
'sentBcc' => '[email protected]', //optional
'replyTo' => '[email protected]', //optional
'body' => $body,
'attach' => array(
array($filePath, $filename, $contentType),
), //optional
'ip' => $request->getClientIp(), //optional
);
//Sends email
$emailSent = $emailService->send($emailData, [saveDatabase ? true|false(default)]);
//You can test if email has been sent
if ($emailSent) {
//Do what you need...
} else {
//Do what you need...
}
// ...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.