HostGator 不会通过 PHP SwiftMail API 发送邮件
PHP 版 SwiftMail API 无法在 HostGator 上运行是否有原因?他们的技术支持人员表示,使用 mail() 命令,到端口 25 的套接字连接将无法像他们的共享托管计划那样工作。我抱怨说,当你在谷歌上搜索如何使用 mail() 发送附件时,人们告诉你使用 SwiftMail。 我需要通过电子邮件发送文件附件。
我的代码在 A2Hosting 上运行良好,但在 HostGator 上运行不正常。在 API 中,我在端口 25 上发送到本地主机,不使用身份验证,不使用 SSL,并使用该主机上确实存在的有效电子邮件地址(假设它是 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 上工作,请分享您所做的事情。
Is there a reason why SwiftMail API for PHP won't run on HostGator? Their tech support said use the mail() command and that socket connections to port 25 won't work like that on their shared hosting plan. I complained and said that when you google on how to send attachments with mail(), people tell you to use SwiftMail. I need to send file attachments with the email.
My code works just fine on A2Hosting, but not HostGator. In the API, I'm sending to localhost on port 25, using no authentication, using no SSL, and using a valid email address that does exist on this host (pretend it's example.com) -- [email protected].
The error I'm getting is:
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
If you've gotten SwiftMail API to work on HostGator, please share what you did.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以尝试使用
Swift_MailTransport
而不是Swift_SmtpTransport
,后者将在幕后使用本机mail()
调用。我没有使用 HostGator 的经验,但如果他们的支持人员说系统允许通过
mail()
发送,这应该可以正常工作。You can try using
Swift_MailTransport
instead ofSwift_SmtpTransport
which will use the nativemail()
call behind the scenes.I have no experience with HostGator but if their support says the system allows sending through
mail()
this should work fine.我进行了一些测试并最终找到了答案。它确实有效,但具体方法如下:
I ran some tests and found the answer finally. It does work, but here's how:
事实证明,如果您尝试发送到 CPanel 中的域,即使您在其他地方托管了电子邮件,他们的邮件服务器也会尝试将邮件中继到本地邮箱,而不是查询该域的 MX 记录。
修复方法是告诉他们从 exim 邮件服务器配置文件中的 localhost 选项中删除您尝试发送电子邮件的域。
Turns out if you are trying to send to a domain that is in your CPanel, even if you have email hosted somewhere else, their mail server tries to relay the message to a local mailbox instead of consulting the MX records for the domain.
The fix is to tell them to remove the domain you are trying to email from their localhost option in their exim mail server configuration file.
我正在将 SwiftMail for PHP 与 hostgator 一起使用,并使用 Swift_SmtpTransport 通过 ssl 连接到 gmail。起初,我收到一条“无法与主机 smtp.gmail.com 建立连接 [连接被拒绝#111]”。使用 Swift_MailTransport 确实有效,但我不喜欢这个解决方案,因为它会使用 hostgator 的邮件服务器;我想使用谷歌应用程序电子邮件帐户来发送电子邮件。
我必须要求 HostGator 的技术支持将 cPanel 用户列入 SMTP 防火墙的白名单,然后一切正常。
I am using SwiftMail for PHP with hostgator with Swift_SmtpTransport connecting to gmail over ssl. At first I was getting a "Connection could not be established with host smtp.gmail.com [Connection refused #111]". Using Swift_MailTransport did work, but I did not like that solution because it would use hostgator's mail server; I wanted to use a google apps email account to send the email.
I had to ask HostGator's tech support to whitelist the cPanel user in the firewall for SMTP, and then everything worked well.
你确定邮件服务器在同一个盒子上吗?您是否尝试挖掘 example.com 的 mx 记录
are you sure the mailserver is on the same box? did you tried to dig the mx record of example.com
我在尝试使用 Amazon 的简单邮件服务发送电子邮件时遇到此错误。最终证明我使用 AmazonSES 的凭据是错误的。一旦我得到了这个正确的结果,所有的事情就都解决了。
顺便说一句,我正在使用 PHP 的 Swift_SmtpTransport
I got this error while trying to send emails using Amazon's Simple Mail Service. Ultimately it turned out to be my credentials for using AmazonSES were wrong. Once i got this correct every thing resolved out for me.
By the way I was using PHP's Swift_SmtpTransport