我使用swift邮件程序为我的symfony应用程序发送电子邮件。但是它抛出错误: 没有扩展程序可以加载“传输”的配置。我在加载应用程序崩溃的配置文件时收到错误。请帮助我知道如何准确定义它的配置参数。 我的app / config.yml就像:
swiftmailer:
transport: gmail
username: 'myemail@example.com'
password: 'Mypassword'
我还检查了app / Appkernel.php swiftmailer bundle已经注册:
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.
答案 0 :(得分:1)
你的缩进是错误的。它应该像..
swiftmailer:
transport: gmail
username: 'myemail@example.com'
password: 'Mypassword'