【问题标题】:Can't send E-Mails with symfony and swiftmailer using SMTP Server无法使用 SMTP 服务器使用 symfony 和 swiftmailer 发送电子邮件
【发布时间】:2019-05-17 20:59:47
【问题描述】:

当我尝试发送电子邮件时出现错误:

刷新电子邮件队列时发生异常:无法连接 与主机 w00d8ef1.kasserver.com [#0]

建立

.env

MAILER_URL=smtp://w00d8ef1.kasserver.com:25?encryption=ssl&auth_mode=login&username=myusername&password=mypassword

swiftmailer.yaml

swiftmailer:
    url: '%env(MAILER_URL)%'
    spool: { type: 'memory' }

控制器:

$message = (new Swift_Message('Test'))
    ->setFrom('info@lama.resper.de')
    ->setTo($user->getEmail())
    ->setBody(
        $this->renderView(
            'pdf/usercard.html.twig',
            ['user' => $user]
        ),
        'text/html'
    )
;
$mailer->send($message);

希望有人可以帮助我。邮件服务器正在运行。

【问题讨论】:

  • SMTP 服务器上是否有防火墙阻止您的连接?
  • 您确定 smtp 在端口 25 上吗?通常 SMTP 在 465 或 587 上运行
  • @JessGabriel 是 465 端口,请写成答案,然后我会接受。
  • 完成@Laire。我已将其添加为响应

标签: symfony email smtp symfony4 swiftmailer


【解决方案1】:

您确定您为 smtp 使用了正确的端口号吗?通常,它在 465 或 587 上运行。因此,请尝试更改 MAILER_URL 环境变量中的端口号。

【讨论】:

    【解决方案2】:

    symfony 4.3

    试试 .env 文件的样子

    MAILER_URL=smtp://YOURDOMAIN.COM:465?encryption=ssl&auth_mode=login&username=USEREMAIL@DOMAIN.COM&password=YOURPASSWORD

    在 config/packages/dev/swiftmailer.yaml 中(用于开发环境) 插入:

    swiftmailer:
    transport:        smtp
    username:         user@domain.pl
    password:         'yourpasswor{$#@'
    host:             mail.yourdomain.pl
    port:             465
    encryption:       ssl
    auth-mode:        login
    spool: { type: 'memory' }
    stream_options:
        ssl:
            allow_self_signed: true
            verify_peer: false
            verify_peer_name: false
    

    使用

    php bin/console debug:config swiftmailer
    

    检查你的配置

    与生产 yaml 文件相同(但 ssl 不应自签名)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2012-06-10
      • 2016-09-07
      • 1970-01-01
      • 2012-10-20
      • 2013-02-23
      • 1970-01-01
      相关资源
      最近更新 更多