HostGator 不会通过 PHP SwiftMail API 发送邮件

发布于 2024-12-01 08:53:54 字数 1832 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

装纯掩盖桑 2024-12-08 08:53:55

您可以尝试使用 Swift_MailTransport 而不是 Swift_SmtpTransport,后者将在幕后使用本机 mail() 调用。

我没有使用 HostGator 的经验,但如果他们的支持人员说系统允许通过 mail() 发送,这应该可以正常工作。

You can try using Swift_MailTransport instead of Swift_SmtpTransport which will use the native mail() 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.

回忆凄美了谁 2024-12-08 08:53:55

我进行了一些测试并最终找到了答案。它确实有效,但具体方法如下:

  • 使用端口 25,而不是替代端口
  • 不要使用 SSL/TLS
  • 使用用户/密码不是必需的,但无论有没有它都可以工作
  • 不要使用“localhost”——使用名称邮件帐户所在的域,无论是根域、附加域、子域还是停放域,
  • 请确保发送电子邮件帐户存在,并且存在于您想要的域上下文中。例如,我可能将 example1.com 作为根域,将 example2.com 作为我的项目的插件域。因此,在我的项目代码中,我将创建一个 [email protected] cPanel 中的帐户,然后使用它作为发送电子邮件地址使用 SwiftMailer API。

I ran some tests and found the answer finally. It does work, but here's how:

  • use port 25, not an alternative port
  • do not use SSL/TLS
  • using a user/pass is not necessary, but will work with or without it
  • do not use 'localhost' -- use the name of the domain where the mail account exists, whether it's the root domain, addon domain, subdomain, or parked domain
  • ensure that the sending email account exists, and exists in the domain context you want. For instance, I may have example1.com as the root domain, and example2.com as the addon domain for my project. So, in my project code, I'll create a [email protected] account in cPanel and then use this as the sending email address with the SwiftMailer API.
桃气十足 2024-12-08 08:53:55

事实证明,如果您尝试发送到 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.

双马尾 2024-12-08 08:53:55

我正在将 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.

爱的故事 2024-12-08 08:53:55

使用此主机上确实存在的有效电子邮件地址(假设它是
example.com) -- [电子邮件受保护]

你确定邮件服务器在同一个盒子上吗?您是否尝试挖掘 example.com 的 mx 记录

using a valid email address that does exist on this host (pretend it's
example.com) -- [email protected].

are you sure the mailserver is on the same box? did you tried to dig the mx record of example.com

守望孤独 2024-12-08 08:53:55

我在尝试使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文