Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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
Php 在symfony中加载swift邮件程序时出错_Php_Symfony_Swiftmailer - Fatal编程技术网

Php 在symfony中加载swift邮件程序时出错

Php 在symfony中加载swift邮件程序时出错,php,symfony,swiftmailer,Php,Symfony,Swiftmailer,我使用swift mailer为我的symfony应用程序发送电子邮件。但它抛出了错误: 没有能够加载“传输”配置的扩展。当应用程序崩溃时,我在加载配置文件时收到错误。请帮助我了解如何准确定义其配置参数。 我的app/config.yml类似于: swiftmailer: transport: gmail username: 'myemail@example.com' password: 'Mypassword' 我还检查了app/Appkernel.php swiftmailer捆绑包是否已

我使用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.

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

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

这可能是多种情况:不正确的细节,线轴不清空,等等。我会尝试用你的问题和细节开始一个新问题。