[英]swiftmailer does not send emails
I want to send emails using symfony, but the swiftmailer does not send out any emails. 我想使用symfony发送电子邮件,但是swiftmailer不会发送任何电子邮件。 I even dont get error reportings or anything else.
我什至没有收到错误报告或其他任何内容。 Thats my code:
那就是我的代码:
$mail = \Swift_Message::newInstance()
->setSubject('Subject')
->setTo('test@example.com') #this is replaced by real email of course
->setFrom('test@example.com')
->setBody('Testbody');
$this->get('mailer')->send($mail);
Thats the config: 多数民众赞成在配置:
swiftmailer:
default_mailer: mailer
mailers:
mailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
#spool: { type: memory }
I even tried to set the host to an address that does not exist, but I dont get any error from swiftmailer or symfony. 我什至试图将主机设置为一个不存在的地址,但是我没有从swiftmailer或symfony中得到任何错误。
I tried to find the files for the lib, but there is no Swift_Message or newInstance anywhere in the symfony files, strange 我试图找到lib的文件,但是symfony文件中的任何地方都没有Swift_Message或newInstance,这很奇怪
use this code 使用此代码
$message = \Swift_Message::newInstance()
->setSubject('Validation de votre commande')
->setFrom('test@example.com')
->setTo('test@example.com')
->setBody('Testbody');
->setCharset('utf-8')
->setContentType('text/html')
->setBody('test');
$this->get('mailer')->send($message);
in app/config/parametres.yml : 在app / config / parametres.yml中:
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: your mail
mailer_password: your password mail
in app/config/config.yml : 在app / config / config.yml中:
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I had seen someone with the same problem. 我见过有人遇到同样的问题。 For him the problem was with the spool queue.
对他来说,问题在于假脱机队列。 It is solved by either disabling spool explicitly:
可以通过显式禁用假脱机来解决此问题:
spool:
enabled:false
or flushing the queue in the code: 或刷新代码中的队列:
$this->get('mailer')->send($mail);
$spool = $this->get('mailer')->getTransport()->getSpool();
$spool->flushQueue($this->get('mailer')->getTransport());
Hope it works! 希望它能起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.