我开发了一个 yii2 应用程序并将其部署在 Bluehost 上的 CPanel 中。我在 CPanel 中创建了一个电子邮件帐户,以使用 swiftmailer 发送电子邮件。当我在本地主机(我的电脑)中使用电子邮件时,它工作正常。但是,当我在 CPanel 中运行它时,即使结果是 true 并且在日志中没有发现错误,它也不会发送电子邮件。托管应用程序如何发送电子邮件?应该改变什么配置?我尝试更新 SPF 记录,但不起作用。我检查了电子邮件限制并连接设备详细信息。
CPanel 中托管的项目的发件人域是一个子域:api.mydomainname.com 该域名托管在同一台服务器上。
邮箱配置如下:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,
// 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.
'transport' => [
'class' => 'Swift_SmtpTransport',
//'host' => 'smtp.office365.com',
'host' => 'mail.mydomainname.com',
'port' => '587',
'username' => '[email protected]',
'password' => 'pass',
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
],
]
我尝试更新 SPF 记录,但不起作用。 将端口更改为 25 和 465,并将加密更改为 ssl。连接失败。
当我更改发件人电子邮件(使用[电子邮件受保护])和主机(outlook.office365.com)时,它工作正常。
我将主机更改为mail。(我的bluehost CPanel的主域)并且它起作用了