Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 呈现邮件模板zend framework 2_Zend Framework2 - Fatal编程技术网

Zend framework2 呈现邮件模板zend framework 2

Zend framework2 呈现邮件模板zend framework 2,zend-framework2,Zend Framework2,我正在尝试发送一封带有Zend framework 2应用程序模板的电子邮件。 这是我班上叫做“EmailService…”的代码 一切正常,但在这个模板文件中,我必须创建一个指向某个操作的链接(我已经为此指定了路径)。但这里有一个问题。因为当我试图使用 <?php echo $this->url('auth') ; ?> 我有“未提供RouteStackInterface实例”错误 如果我使用: <?php echo $this->serverUrl(tru

我正在尝试发送一封带有Zend framework 2应用程序模板的电子邮件。 这是我班上叫做“EmailService…”的代码

一切正常,但在这个模板文件中,我必须创建一个指向某个操作的链接(我已经为此指定了路径)。但这里有一个问题。因为当我试图使用

<?php echo $this->url('auth') ; ?>

我有“未提供RouteStackInterface实例”错误

如果我使用:

<?php echo $this->serverUrl(true); ?>


一切正常。。。有什么线索吗?

您不需要创建
PhpRenderer的新实例;您可以重用已经创建的一个

$renderer = $this->serviceManager->get('viewrenderer');

$variables = is_array($template['variables']) ? $template['variables'] : array();
$viewModel = new ViewModel($variables);
$viewModel->setTemplate('mailTemplate');

$html = $renderer->render($viewModel);
为了遵循良好的DI实践,将
PhpRenderer
注入电子邮件服务的
\u结构(而不是服务管理器)

另外,模板路径可以添加到普通的
module.config.php

return array(
    'view_manager' => array(
        'template_map' => array(
            'mailTemplate' => __DIR__ . '/../view/foo/bar.phtml',
        ),
    ),
);

在发送html邮件时,有许多模块使事情变得简单。你可以搜索它们

我个人最喜欢的是。您可以轻松使用模板和布局。您可以轻松设置默认标题(发件人、回复收件人等)。您可以使用此功能以面向对象的方式更好地组织电子邮件模板

MtMail使用情况:
return array(
    'view_manager' => array(
        'template_map' => array(
            'mailTemplate' => __DIR__ . '/../view/foo/bar.phtml',
        ),
    ),
);
$mailService = $this->getServiceLocator()->get('MtMail\Service\Mail');

$headers = array(
    'to' => 'johndoe@domain.com',
    'from' => 'contact@mywebsite.com',
);
$variables = array(
    'userName' => 'John Doe',
);
$message = $mailService->compose($headers, 'application/mail/welcome.phtml', $variables);

$mailService->send($message);