SwiftMail API for PHP 不能在 HostGator 上运行有什么原因吗?他们的技术支持人员说使用 mail() 命令并且到端口 25 的套接字连接在他们的共享主机计划中不会像那样工作。我抱怨说,当你在谷歌上搜索如何使用 mail() 发送附件时,人们会告诉你使用 SwiftMail。我需要用电子邮件发送文件附件。
我的代码在 A2Hosting 上运行良好,但在 HostGator 上运行良好。在 API 中,我在端口 25 上发送到 localhost,不使用身份验证,不使用 SSL,并且使用此主机上确实存在的有效电子邮件地址(假设它是 example.com)—— noreply@example.com。
我得到的错误是:
Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:25 (Connection refused) in /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Transport/StreamBuffer.php on line 243
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host localhost [Connection refused #111]' in /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Transport/StreamBuffer.php:245 Stack trace: #0 /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Transport/StreamBuffer.php(80): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Transport/AbstractSmtpTransport.php(111): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Mailer.php(84): Swift_Transport_AbstractSmtpTransport->start() #3 /home/user/public_html/mywebsite/mailer.php(34): Swift_Mailer->send(Object(Swift_Message)) #4 /home/user/public_html/mywebsite/mailer.php(146): Mailer->sendMail() #5 {main} thrown in /home/user/public_html/mywebsite/addons/swiftmail-4.0.3/lib/classes/Swift/Transport/StreamBuffer.php on line 245
如果你已经让 SwiftMail API 在 HostGator 上工作,请分享你所做的。