【发布时间】:2016-10-23 13:54:05
【问题描述】:
我正在尝试使用依赖注入器在 Phalcon 3 上加载 SwiftMailer,但我收到有关 Swift_transporter 服务的错误。
Phalcon\Di\Exception:在依赖注入容器中找不到服务“\Swift_SmtpTransport”
我想知道如何在依赖注入器中加载 Swift_SmtpTransport 服务,无需作曲家。我知道composer可以轻松解决这个问题,但我想知道是否还有其他选择。
在我的 service.php 文件中,我添加了下一行:
$di->set('mailer', function(){
$mailer = new Manager([
'driver' => 'sendmail',
'sendmail' => '/usr/sbin/sendmail -bs',
'viewsDir' => $this->config->application->viewsDir . 'emails/',
'from' => [
'email' => 'notify@website.com',
'name' => 'Company Team'
]
]);
return $mailer;
});
然后我用下一行调用服务:
$this->mailer([
'to' => 'email@test.com',
'name' => 'First and Last Name',
'subject' => _('Welcome to my website'),
'body' => [
'view' => 'welcome',
'params' => [
'name' => 'First Name',
'link' => $this->url->get('users/activate/?email=email@test.com&activation_key=******')
]
]
]);
【问题讨论】:
标签: php dependency-injection phalcon swiftmailer