Php 电子邮件不';t发送Swiftmailer Symfony2
我使用Swiftmailer在我的Symfony 2.5项目中发送电子邮件。这是我的相关代码 参数.yml config.ymlPhp 电子邮件不';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 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类型是内存而不是文件?