首页 > 解决方案 > Yii2 联系我们页面与 Swiftmailer

问题描述

我将 yii2 basic 与 Yii2 一起使用的 swiftmailer 一起使用。

我不是用它来发送电子邮件,只是通过我的contact us页面接收消息。我收到了各种消息,在尝试使用我的谷歌电子邮件时,我收到了与安全相关的错误,谷歌查看我的应用程序可能是恶意的,即使我allowed less secure apps accessing my account打开了。

我实际上想使用随@domain.com. 我的托管服务提供商是hostgator,所以假设我admin@domain.com用我的 cpanel 做了一个。

我已经adminEmail=>admin@domain.com在我的参数中设置了我的,并在我的网络配置中配置了传输数组

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
            'host' => 'mail.domain.com',
            'username' => 'admin@domain.com',
            'password' => '*****',
            'port' => '993',
            'encryption' => 'ssl',
    ],

这是我的电子邮件 smtp 设置hostgator (出于隐私考虑,我将实际域名更改为domain.com


Username:   admin@domain.com
Password:   Use the email account’s password.
Incoming Server:    mail.domain.com
IMAP Port: 993 POP3 Port: 995
Outgoing Server:    mail.domain.com
SMTP Port: 465
IMAP, POP3, and SMTP require authentication.

如您所见,我只需要它来接收电子邮件,而不是发送出去,所以我将端口设置为993, 和稍后995。我还尝试'class' => 'Swift_MailTransport'按照 Stackoverflow 中某些人的建议将我的课程设置为,但仍然收到错误消息:Connection to tcp://mail.domain.com:465 Timed Out

更新:尝试使用传出端口和Swift_MailTransport类组合,但仍然出现相同的错误。

我在这里做错了什么?我真的被困住了。任何帮助将不胜感激。谢谢!

更新:已解决。所以我应该一直使用传出端口(在 SO/google 中,很少有人使用 swiftmailer 来接收电子邮件(大多数人使用它来发送电子邮件),所以我错误地认为我应该使用传入端口。除此之外,我应该为我各自的可用端口配置正确的加密配置。在我的情况下,我的托管服务提供商只为我提供了端口 465,因此加密应该与 匹配ssl。然后它就可以了!感谢@tim 提供提示

标签: phpyii2swiftmailer

解决方案


推荐阅读