发送邮件报错
Connection could not be established with host smtp.sina.com :stream_socket_client(): unable to connect to smtp.sina.com:25 (Connection timed out)
服务器的邮箱服务使用的好好的很稳定,最近突然出错了
尝试了在在本地是可以正常发送邮件,但是相同的配置在腾讯云服务器出错。
网上查了原因是 腾讯云服务器封禁了 25 端口,于在腾讯云服务器控制台开启 25 端口,结果还是报出相同错误
最终解决办法
- 使用 465 端口,
- 设置Encryption 为 ssl
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.sina.com', 465))
->setUsername('xxxxx@sina.com')
->setEncryption('ssl')
->setPassword('xxxxx');
代码仅做参考
我使用的是swiftmailer/swiftmailer包
composer require swiftmailer/swiftmailer
– 结束 –