We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problem with sending multiple swift emails ( template problem? )

Hello,

I am using this class ( https://pastebin.com/C7T8vLKg ) which uses swift to send emails. I trigger the class like this from within a controller: https://pastebin.com/tSh2wN07

When sending 1 email all works fine and as expected, however when i send more then one email inside a controllerAction, only the first email arrives with a body content, all the other emails are emtpy. This makes me think that i am doing something wrong with how I call the template and render it.

Anybody any ideas how i can send multiple emails within one controller action call? Appreciate any help

p.s. I am using volt template engine in my project but i also tried sending only static html, same outcome



58.4k

Hey man

In class Mail I see use have function

public function getTemplate($name, $params) {
        $parameters = array_merge(array(
            'publicUrl' => "website.com",
        ), $params);
        return $this->view->getRender('emailTemplates', $name, $parameters, function($view){
            $view->setRenderLevel(View::LEVEL_LAYOUT);
        });
        return $view->getContent();
    }

You shoud change it to follwoing codev

public function getTemplate($name, $params) {
        $parameters = array_merge(array(
            'publicUrl' => "website.com",
        ), $params);
        $this->view->getRender('emailTemplates', $name, $parameters, function($view){
            $view->setRenderLevel(View::LEVEL_LAYOUT);
        });
        return $this->view->getContent();
    }


3.2k

I applied the changes you suggested but now all emails are emtpy



3.2k
edited May '15

I found the problem inside my index.php

    $view->registerEngines(array(
        ".volt" => 'volt'
    ));

that is how i registerd the template engine, changing this to

$view->registerEngines(array(
    ".volt" => function($view, $di) {
        return new \Phalcon\Mvc\View\Engine\Volt($view, $di);
    }
));

did the trick for me