【问题标题】:Swiftmailer symfony2.2 always sent 0 emailsSwiftmailer symfony2.2 总是发送 0 封邮件
【发布时间】:2013-06-04 18:37:28
【问题描述】:

我有以下 swiftmailes 配置

# config.yml
swiftmailer:
    transport: stmp
    host:      mail.domain.com
    port:      25
    username:  myuser
    password:  mypass
    spool:
        type: file
        path: "%kernel.cache_dir%/swiftmailer/spool"
    logging:  "%kernel.debug%"

以及以下发送消息的代码

$subject = "TESTING";

$mailer = $this->getContainer()->get('mailer');
$message = \Swift_Message::newInstance()
    ->setSubject($subject)
    ->setFrom("noreply@domain.com")
    ->setTo("julian.reyes.escrigas@gmail.com")
    ->setBody("Body message");

$mailer->send($message);

发送消息后,这可以在app/cache/dev/swiftmailer/spool 创建,但是当我调用命令时

$ app/console swiftmailer:spool:send --message-limit=10 --env=dev

假脱机中的所有消息都会消失,但不会发送到接收者。

注意:我已经在客户端(thunderbird)上尝试过 STMP 设置并且工作正常


测试

出于测试目的,我尝试在没有队列的情况下直接发送消息

$message = \Swift_Message::newInstance()
    ->setSubject($subject)
    ->setFrom("noreply@domain.com")
    ->setTo("julian.reyes.escrigas@gmail.com")
    ->setBody("Body message");

$mailer->send($message);

$transport  = $this->getContainer()->get('swiftmailer.transport.real');
$transport->start();

// but count alwasy is zero
$count = $transport->send($message);

我已经尝试了 config.yml 文件中的所有组合

auth_mode:  plain / login / null
encryption: tsl / ssl / null
port: 25 / 465

从 symfony 分析器我得到

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Date: Tue, 04 Jun 2013 14:33:12 -0500
Message-ID: <1370374392.51ae40f8b6202@localtest>
From: noreply@mydomain.com
Subject: TEST
To: julian.reyes.escrigas@gmail.com
Mensaje de prueba de Texto

测试 2

我开始认为这可能是我安装的版本有问题。我试过直接创建 SMTP 传输但没有成功

$message = \Swift_Message::newInstance()
    ->setSubject("TEST")
    ->setFrom("noreply@domain.com")
    ->setTo(array("julian.reyes.escrigas@gmail.com"))
    ->setBody("Mensaje de prueba de Texto");


$transport = \Swift_SmtpTransport::newInstance('mail.domain.com', 25)
    ->setUsername('noreply@domain.com')
    ->setPassword('THEPASS');

$mailer = \Swift_Mailer::newInstance($transport);

$transport->start();
// ZERO again
$output->writeln(sprintf("Mensajes enviados: %s", $mailer->send($message)));

注意 2:我已经尝试使用 PHpMailer 并使用相同的设置发送邮件没有问题,但我想使用 swiftmailer

注意 3:使用本地设置在我的托管服务提供商上进行测试可以正常工作。但是如果不使用棘手的 ssh 隧道,我就无法从自己的笔记本电脑(开发环境)进行测试

transport: mail
host: localhost
username: ~
password: ~
  • PHP 5.4.6
  • Symfony 2.2.2
  • Swiftmailer 5.0

【问题讨论】:

  • 不,我认为添加选项“日志”附加信息到 dev.log 但没有
  • 您打算使用哪个 smtp 客户端?其中一些需要一个非标准的端口。其中一些需要不同的身份验证。 Thunderbird 可以自动处理检查这些情况,这就是为什么它可能会起作用,但在这里可能不起作用。
  • 在雷鸟中我禁用了加密并将配置设置为手动等于 swiftmailer
  • 可以试试telnet吗?
  • %kernel.debug% 是真的吗?如果是,您应该能够在不使用队列时看到分析器中的日志。

标签: php symfony swiftmailer


【解决方案1】:

你确定这不仅仅是一个错字吗?

transport: stmp

=>

transport: smtp

【讨论】:

    【解决方案2】:

    如果有人要找答案:尝试在setFrom()方法中设置有效的电子邮件地址;在我的情况下,像“noreply@domain.com”这样的虚拟电子邮件被假脱机,但传递失败。在指定有效地址后,它发送了一封电子邮件(终于!)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多