Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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 电子邮件不';t发送Swiftmailer Symfony2_Php_Email_Symfony_Swiftmailer - Fatal编程技术网

Php 电子邮件不';t发送Swiftmailer Symfony2

Php 电子邮件不';t发送Swiftmailer Symfony2,php,email,symfony,swiftmailer,Php,Email,Symfony,Swiftmailer,我使用Swiftmailer在我的Symfony 2.5项目中发送电子邮件。这是我的相关代码 参数.yml config.yml # Swiftmailer Configuration swiftmailer: transport: smtp encryption: ssl auth_mode: login host: smtp.xx.eu username: username password: password 控制

我使用Swiftmailer在我的Symfony 2.5项目中发送电子邮件。这是我的相关代码

参数.yml

config.yml

# Swiftmailer Configuration
swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.xx.eu
    username:   username
    password:   password 
控制器:

$message = \Swift_Message::newInstance()
        ->setSubject('mana')
        ->setFrom('***@gmail.com')
        ->setTo('***@yahoo.com')
        ->setBody('this is test');
    $this->get('mailer')->send($message);
$message = \Swift_Message::newInstance()
    ->setSubject('mana')
    ->setFrom('****@gmail.com')
    ->setTo('mana@yahoo.com')
    ->setBody('this is test');
# I removed this line: $this->get('mailer')->send($message);

$mailer = $this->get('mailer');

$mailer->send($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
我在
appKernel.php

$bundles = array(
        ...
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        ...
    );

电子邮件未被发送。你能帮我吗?

以下代码在命令中工作,但我为控制器修改了它:

$message = \Swift_Message::newInstance()
        ->setSubject('mana')
        ->setFrom('***@gmail.com')
        ->setTo('***@yahoo.com')
        ->setBody('this is test');
    $this->get('mailer')->send($message);
$message = \Swift_Message::newInstance()
    ->setSubject('mana')
    ->setFrom('****@gmail.com')
    ->setTo('mana@yahoo.com')
    ->setBody('this is test');
# I removed this line: $this->get('mailer')->send($message);

$mailer = $this->get('mailer');

$mailer->send($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
来源:.

config.yml

# Swiftmailer Configuration
swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.xx.eu
    username:   username
    password:   password 
控制员/行动

$messageObject = \Swift_Message::newInstance()
            ->setSubject('Subject')
            ->setFrom('username@xx.eu')
            ->setTo('xxx@stackoverflow.eu')
            ->setBody('message');
$this->get('mailer')->send($messageObject);
parameters.yml-默认值

mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null

请看.Tnx@A.L,但事实上我想立即发送电子邮件,spool一点都不重要!您的问题可能来自SMTP服务器,因为您的代码正常。@MaNa我很高兴它能为您工作。但根据我的回答中链接的文档,如果后台处理配置正确,则不需要此代码,我建议您遵循文档中的指导原则。我的服务中没有使用“仅发送”发送电子邮件,我必须使用flushQueue方法才能最终发送。当我运行php应用程序/控制台swiftmailer:spool:send时,它说0封电子邮件是因为我的spool类型是内存而不是文件?