【问题标题】:Error loading swift mailer in symfony在 symfony 中加载 swift mailer 时出错
【发布时间】: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


    【解决方案1】:

    你的缩进是错误的。应该是这样的。。

    swiftmailer:
        transport: gmail
        username: 'myemail@example.com'
        password: 'Mypassword'
    

    【讨论】:

    • 这可能是各种各样的事情:不正确的详细信息、线轴未清空等。我会尝试使用您的问题和详细信息打开一个新问题。
    猜你喜欢
    • 2019-05-25
    • 2022-01-08
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 2016-02-18
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多