【问题标题】:send method is always returning 0send 方法总是返回 0
【发布时间】:2015-04-21 14:05:27
【问题描述】:

我正在使用 swift_mailer 处理发送电子邮件,但我遇到了一个问题,即电子邮件没有发送,send 方法的返回值始终为零。

app/config/config.yml

swiftmailer:
   transport: smtp
   host:      <host>  # of the company
   username:  <username> # of the company
   password:  <password> # of the company
   port: 25

app/config/config_test.yml

swiftmailer:
    disable_delivery: true
    # disable_delivery: ~ # tried with this too

控制器

$mailer = $this->get('mailer');
$message = $mailer->createMessage()
    ->setSubject('You have Completed Registration!')
    ->setFrom('send@example.com')
    ->setTo('valid_email@Iswear.fr')
    ->setBody(
        'hello world!!',
        'text/plain'
    )

var_dump($mailer->send($message, $failed), $failed); exit;

输出:

int(0)
array(0) {
}

我知道 send 返回电子邮件已发送给的人数。为什么永远不会发送电子邮件? 鉴于我确定我要发送到的唯一电子邮件地址。

更新1:

我想知道如何进一步调试。

【问题讨论】:

  • 你在哪个环境? disable_delivery 不发送任何电子邮件,(用于测试或开发...)
  • swiftmailer: disable_delivery: 在开发环境中为真 => 在开发环境中永远不会发送电子邮件
  • 尝试 disable_delivery: false
  • @pcm 这是预期的,但发送方法应该返回 1,不是吗?
  • 不一定。如果你想实现一个测试环境,disable_delivery 不是答案。

标签: php email symfony smtp swiftmailer


【解决方案1】:

如果要实现测试环境的mailer,不要使用disable_delivery。
这完全禁用了 swiftmailer 的发送。
使用

# app/config/config_dev.yml
swiftmailer:
      disable_delivery: false
      delivery_address: dev@example.com # some test or development email account

【讨论】:

  • 实际上这个 disable_delivery 语句应该设置为 false,正如你所说:disable_delivery: false,请更新你的答案,以便我可以将其标记为已解决我的问题
  • 已编辑。如果您需要进一步的帮助,请随时询问:)
【解决方案2】:

也许你的配置有错误。尝试使用记录器进行调试输出: http://swiftmailer.org/docs/plugins.html#logger-plugin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2014-07-02
    • 2015-09-27
    • 2014-03-20
    • 2013-04-13
    相关资源
    最近更新 更多