【发布时间】:2014-08-31 17:44:57
【问题描述】:
我正在使用 swift mailer 为我的 symfony 应用程序发送电子邮件。但它抛出了错误: 没有扩展能够加载“传输”的配置。加载应用程序崩溃的配置文件时出现错误。请帮助我了解如何准确定义它的配置参数。 我的 app/config.yml 是这样的:
swiftmailer:
transport: gmail
username: 'myemail@example.com'
password: 'Mypassword'
我还检查了 app/Appkernel.php swiftmailer 捆绑包是否已注册:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Acme\SuperbAppBundle\AcmeSuperbAppBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
我正在使用以下代码发送电子邮件:
$message = \Swift_Message::newInstance()
->setSubject('Hello Email') // we configure the title
->setFrom('myemail@example.com') // we configure the sender
->setTo('someone@example.com') // we configure the recipient
->setBody("Hello User");
$send = $this->get('mailer')->send($message); // then we send the message.
【问题讨论】:
标签: php symfony swiftmailer