From 4236a16e492a61330b3f5d151149ced240f8455b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 18:04:48 +0200 Subject: [PATCH] create example for mail usage --- .../Thelia/Config/Resources/routing/front.xml | 4 ++ core/lib/Thelia/Controller/BaseController.php | 13 +++++ core/lib/Thelia/Controller/Front/Mail.php | 49 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 core/lib/Thelia/Controller/Front/Mail.php diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 351ba2ab4..542a1a319 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -164,4 +164,8 @@ + + Thelia\Controller\Front\Mail::test + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index e9f359411..548ef9681 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -303,4 +303,17 @@ class BaseController extends ContainerAware return $mailer->getSwiftMailer(); } + + /** + * @return ParserInterface instance parser + */ + protected function getParser() + { + return $this->container->get("thelia.parser"); + } + + protected function render($inline) + { + return $this->getParser()->fetch(sprintf("string:%s", $inline)); + } } diff --git a/core/lib/Thelia/Controller/Front/Mail.php b/core/lib/Thelia/Controller/Front/Mail.php new file mode 100644 index 000000000..dfaf2d4fa --- /dev/null +++ b/core/lib/Thelia/Controller/Front/Mail.php @@ -0,0 +1,49 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; + + +/** + * Class Mail + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +class Mail extends BaseFrontController +{ + /** + * This is a demo how to send a mail using swiftmailer + smarty + */ + public function test() + { + $message = \Swift_Message::newInstance('Wonderful Subject') + ->setFrom(array('john@doe.com' => 'John Doe')) + ->setTo(array('mraynaud@openstudio.fr' => 'name')) + ->setBody($this->render('Here is the message itself')) + ; + + $this->getMailer()->send($message); + + exit; + } +} \ No newline at end of file