简体   繁体   English

swiftmailer不发送电子邮件

[英]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.

相关问题 Symfony Swiftmailer:有条件地假脱机电子邮件或立即发送 - Symfony Swiftmailer: Conditionally spool emails or send immediately Symfony 3.4和Swiftmailer-是否可以立即/不假脱机发送电子邮件? - Symfony 3.4 and Swiftmailer - is it possible to send emails immediately/without spool? 无法在symfony2.3应用程序中使用swiftmailer通过gmail发送电子邮件 - Unable to send emails through gmail with swiftmailer in symfony2.3 application 如何在Symfony2中通过Swiftmailer发送12 000封电子邮件? - How to send 12 000 emails via Swiftmailer in Symfony2? Symfony2 SwiftMailer-如何在不等待服务器响应的情况下发送电子邮件 - Symfony2 SwiftMailer - How to send emails without waiting for the server response 带有swiftmailer和Symfony 2的电子邮件标题 - Emails headers with swiftmailer and Symfony 2 如何从运行在 Windows 10 上的本地机器使用 Symfony 4 Swiftmailer 发送电子邮件? - How to send emails with Symfony 4 Swiftmailer from a local machine running on Windows 10? 尝试使用SwiftMailer发送带有Symfony 2的电子邮件:无法与主机smtp.gmail.com [#0]建立连接 - Trying to send emails with Symfony 2 using SwiftMailer : Connection could not be established with host smtp.gmail.com [ #0] Swiftmailer 不从 Hyper-V 虚拟机发送 - Swiftmailer does not send from Hyper-V virtual machine 没有发送Symfony / Swiftmailer电子邮件,也没有日志 - Symfony/Swiftmailer emails not sent and no logs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM