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

Vokuro can't load Mail template

Hi,

i have a problem with Vokuro Mail.php. The emails were send, but the content is always empty.

The getTemplate functition can't load the confirmation.volt.

    public function getTemplate($name, $params)
    {
        $parameters = array_merge([
            'publicUrl' => $this->config->application->publicUrl
        ], $params);
        return $this->view->getRender('emailTemplates', $name, $parameters, function ($view) {
            $view->setRenderLevel(View::LEVEL_LAYOUT);
        });
        return $view->getContent();
    }
    /**
     * Sends e-mails via AmazonSES based on predefined templates
     *
     * @param array $to
     * @param string $subject
     * @param string $name
     * @param array $params
     * @return bool|int
     * @throws Exception
     */
    public function send($to, $subject, $name, $params)
    {
        // Settings
        $mailSettings = $this->config->mail;
        $template = $this->getTemplate($name, $params);
        // Create the message
        $message = Message::newInstance()
            ->setSubject($subject)
            ->setTo($to)
            ->setFrom([
                $mailSettings->fromEmail => $mailSettings->fromName
            ])
            ->setBody($template, 'text/html');
        if (isset($mailSettings) && isset($mailSettings->smtp)) {
            if (!$this->transport) {
                $this->transport = Smtp::newInstance(
                    $mailSettings->smtp->server,
                    $mailSettings->smtp->port,
                    $mailSettings->smtp->security
                )
                ->setUsername($mailSettings->smtp->username)
                ->setPassword($mailSettings->smtp->password);
            }
            // Create the Mailer using your created Transport
            $mailer = \Swift_Mailer::newInstance($this->transport);
            return $mailer->send($message);
        } else {
            return $this->amazonSESSend($message->toString());
        }
    }

When i do this in send function, it works:

$template = '<tbody>
<tr>
    <td style="padding:40px 0  0 0;">
        <p style="color:#000;font-size: 16px;line-height:24px;font-family:\'HelveticaNeue\',\'Helvetica Neue\',Helvetica,Arial,sans-serif;font-weight:normal;">

            <h2 style="font-size: 14px;font-family:\'HelveticaNeue\',\'Helvetica Neue\',Helvetica,Arial,sans-serif;">
                You\'re Almost There! Just Confirm Your Email
            </h2>

            <p style="font-size: 13px;line-height:24px;font-family:\'HelveticaNeue\',\'Helvetica Neue\',Helvetica,Arial,sans-serif;">
                You\'ve successfully created a  account. To activate it, please click below to verify your email address.
            </p>
            <br>
            <br>
                <a style="background:#E86537;color:#fff;padding:10px" href="https://{{ publicUrl }}{{ confirmUrl }}">Confirm</a>
            <br>
            <br>

            <br>
        </p>
    </td>
</tr>

</tbody>';



59.9k
Accepted
answer
edited Jun '17

If anybody is interested, i found a way:

 public function getTemplate($name, $params)
{

    $parameters = array_merge([
        'publicUrl' => $this->config->application->publicUrl
    ], $params);
    $this->view->getRender('emailTemplates', $name, $parameters);
    $this->view->setRenderLevel(View::LEVEL_LAYOUT);

    return $this->view->getContent();
}