php - 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 提供提示
解决方案
推荐阅读
- php - 我应该在哪里添加代码以检查电子邮件是否存在?
- javascript - 尝试向图像添加 mouseenter 和 mouseleave 函数
- networking - 为什么 IP 校验和不只检查 IP 标头中的损坏而不是整个数据报中的损坏?
- c# - 在 c# 中从 MS CRM 中的 LookUp 获取特定字段以获取特定字段的值
- java - 如何检查一个值是否在二维数组的某个位置?
- c# - 如何从 ScrollViewer 中的图像中捕获画布区域
- angular - 上传位于 Angular 项目目录中的文件/图像
- javascript - 使用 fetch api 将图像发送到 nodeJs 服务器
- assembly - 了解 cmp 指令中的派对标志
- solidity - 如何在 Solidity 中使用我的代币修改特定应付函数调用的行为?