Symfony swiftmailer不发送电子邮件
我想用symfony发送电子邮件,但是swiftmailer不发送任何电子邮件。我甚至没有收到错误报告或其他任何东西。这是我的密码:Symfony swiftmailer不发送电子邮件,symfony,swiftmailer,Symfony,Swiftmailer,我想用symfony发送电子邮件,但是swiftmailer不发送任何电子邮件。我甚至没有收到错误报告或其他任何东西。这是我的密码: $mail = \Swift_Message::newInstance() ->setSubject('Subject') ->setTo('test@example.com') #this is replaced by real email of course
$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);
这就是配置:
swiftmailer:
default_mailer: mailer
mailers:
mailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
#spool: { type: memory }
我甚至尝试将主机设置为一个不存在的地址,但是我没有从swiftmailer或symfony那里得到任何错误
我试图找到lib的文件,但symfony文件中没有Swift_消息或newInstance,奇怪的是,请使用此代码
$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);
在app/config/parametres.yml中:
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: your mail
mailer_password: your password mail
在app/config/config.yml中:
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
我见过有同样问题的人。对他来说,问题在于假脱机队列。通过明确禁用假脱机来解决此问题:
spool:
enabled:false
或刷新代码中的队列:
$this->get('mailer')->send($mail);
$spool = $this->get('mailer')->getTransport()->getSpool();
$spool->flushQueue($this->get('mailer')->getTransport());
希望它能起作用 SM配置使用的参数是什么?另外,您是否有正在运行的邮件服务器?是否要获取我的邮件服务器凭据?:)它是一个外部邮件服务器。例如,当我将服务器主机更改为非工作地址时,我甚至没有收到SwiftMailer的任何错误。如果您的外部邮件程序工作正常,则此处显示的代码看起来正常。您确定没有其他东西阻止您的代码发送消息吗?您是否在应用程序的
prod
或dev
环境中尝试过此操作?dev环境,当主机不存在时,我是否应该得到一个错误?为什么你认为我有一个gmail帐户?最好的解决方案是使用gmail帐户,注释应该是负号votet。这远远不是一个解决方案,正如你在我的问题中看到的,sppol没有激活,我甚至检查了它,但没有在那里找到邮件