thedigitalproblemsolver / incubator-mailer
Phalcon 5 Incubator Mailer Adapters
1.0.1
2022-11-13 16:46 UTC
Requires
- php: >=7.4
- ext-json: *
- ext-phalcon: ^5.1.0
- swiftmailer/swiftmailer: ~6.2
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- phalcon/ide-stubs: ^5.1.0
- phpstan/phpstan: ^0.12.18
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.1
- vlucas/phpdotenv: ^2.5
This package is auto-updated.
Last update: 2024-04-13 23:20:29 UTC
README
Usage examples of the mailer wrapper over SwiftMailer for Phalcon:
Configure
SMTP
$config = [ 'driver' => 'smtp', 'host' => 'smtp.gmail.com', 'port' => 465, 'encryption' => 'ssl', 'username' => 'example@gmail.com', 'password' => 'your_password', 'from' => [ 'email' => 'example@gmail.com', 'name' => 'YOUR FROM NAME', ], ];
Sendmail
$config = [ 'driver' => 'sendmail', 'sendmail' => '/usr/sbin/sendmail -bs', 'from' => [ 'email' => 'example@gmail.com', 'name' => 'YOUR FROM NAME', ], ];
Send message
createMessage()
$mailer = new \Phalcon\Incubator\Mailer\Manager($config); $message = $mailer->createMessage() ->to('example_to@gmail.com', 'OPTIONAL NAME') ->subject('Hello world!') ->content('Hello world!'); // Set the Cc addresses of this message. $message->cc('example_cc@gmail.com'); // Set the Bcc addresses of this message. $message->bcc('example_bcc@gmail.com'); // Send message $message->send();
createMessageFromView()
/** To create message with View, you need to define in the DI the component simple View. */ $this->di->set( 'simple', function () { $view = new Phalcon\Mvc\View\Simple(); $view->setViewsDir($config->application->viewsDir); return $view; }, true ); $this->di->setShared('view', function () { $view = new Phalcon\Mvc\View(); $view->setDI($this); $view->setViewsDir($config->application->viewsDir); $view->registerEngines([ '.volt' => function ($view) { $volt = new Phalcon\Mvc\View\Engine\Volt($view, $this); $volt->setOptions([ 'path' => $config->application->cacheDir, 'separator' => '_' ]); return $volt; }, '.phtml' => Phalcon\Mvc\View\Engine\Php::class ]); return $view; }); $mailer = new \Phalcon\Incubator\Mailer\Manager($config); // view relative to the folder viewsDir (REQUIRED) $viewPath = 'email/example_message'; // Set variables to views (OPTIONAL) $params = [ 'var1' => 'VAR VALUE 1', 'var2' => 'VAR VALUE 2', // ... 'varN' => 'VAR VALUE N', ]; $message = $mailer->createMessageFromView($viewPath, $params) ->to('example_to@gmail.com', 'OPTIONAL NAME') ->subject('Hello world!'); // Set the Cc addresses of this message. $message->cc('example_cc@gmail.com'); // Set the Bcc addresses of this message. $message->bcc('example_bcc@gmail.com'); // Send message $message->send();
Events
mailer:beforeCreateMessage
mailer:afterCreateMessage
mailer:beforeSend
mailer:afterSend
mailer:beforeAttachFile
mailer:afterAttachFile