【问题标题】:swiftmailer does not send emailsswiftmailer 不发送电子邮件
【发布时间】:2017-01-30 12:58:22
【问题描述】:

我想使用 symfony 发送电子邮件,但 swiftmailer 不发送任何电子邮件。我什至没有收到错误报告或其他任何东西。这是我的代码:

$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_Message 或 newInstance,奇怪

【问题讨论】:

  • 您使用的 SM 配置所采用的参数是什么?您还有正在运行的邮件服务器吗?
  • 您想要我的邮件服务器凭据吗? :) 它是一个外部邮件服务器。例如,当我将服务器主机更改为非工作地址时,我什至没有收到 swiftmailer 的任何错误
  • 如果您的外部邮件程序工作正常,那么您在此处显示的代码看起来没问题。您确定没有其他东西阻止您的代码发送消息吗?
  • 您是否在应用程序的proddev 环境中尝试过此操作?
  • 开发环境,主机不存在时不应该报错吗?

标签: symfony swiftmailer


【解决方案1】:

使用此代码

    $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 }

【讨论】:

  • 你为什么认为我有一个 gmail 帐户?
  • 最好的办法是使用gmail帐号
  • 该评论应该减去投票。这远非解决方案
【解决方案2】:

我见过有同样问题的人。对他来说,问题在于假脱机队列。它可以通过显式禁用假脱机来解决:

spool:
      enabled:false

或在代码中刷新队列:

$this->get('mailer')->send($mail);
$spool = $this->get('mailer')->getTransport()->getSpool(); 
$spool->flushQueue($this->get('mailer')->getTransport());

希望它有效!

【讨论】:

  • 正如你在我的问题中看到的,sppol 没有被激活,我什至检查了它但没有找到那里的邮件
猜你喜欢
  • 2015-04-16
  • 2019-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多