无法使用 SMTP 服务器使用 symfony 和 swiftmailer 发送电子邮件

Can't send E-Mails with symfony and swiftmailer using SMTP Server

当我尝试发送电子邮件时收到错误消息:

Exception occurred while flushing email queue: Connection could not be established with host 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 端口号正确吗?通常,它在 465 或 587 上运行。因此,请尝试更改 MAILER_URL 环境变量中的端口号。

symfony 4.3

试试 .env 文件就好

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

in 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 不应自签名)