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

时间:2022-09-04 18:13:40

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.

为什么PHP的SwiftMail API不能在HostGator上运行?他们的技术支持说使用mail()命令和套接字连接到端口25在他们的共享主机计划中不会像那样工作。我抱怨说,当你谷歌讨论如何用mail()发送附件时,人们会告诉你使用SwiftMail。我需要随邮件发送文件附件。

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) -- noreply@example.com.

我的代码在a2host上工作得很好,但是在HostGator上不行。在API中,我在端口25上发送到localhost,不使用身份验证,不使用SSL,使用这个主机上存在的有效电子邮件地址(假设它是example.com)——noreply@example.com。

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.

如果您已经获得SwiftMail API来处理HostGator,请分享您所做的。

6 个解决方案

#1


13  

You can try using Swift_MailTransport instead of Swift_SmtpTransport which will use the native mail() call behind the scenes.

您可以尝试使用Swift_MailTransport,而不是使用本地mail()调用的Swift_SmtpTransport。

I have no experience with HostGator but if their support says the system allows sending through mail() this should work fine.

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

#2


4  

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

我做了一些测试,终于找到了答案。它确实有效,但以下是方法:

  • use port 25, not an alternative port
  • 使用端口25,而不是替代端口。
  • do not use SSL/TLS
  • 不使用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
  • 不要使用“localhost”——使用邮件帐户存在的域的名称,无论是根域、addon域、子域还是已停止的域
  • 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 noreply@example2.com account in cPanel and then use this as the sending email address with the SwiftMailer API.
  • 确保发送电子邮件帐户存在,并存在于您想要的域环境中。例如,我可能有example1.com作为根域,而example2.com作为我的项目的addon域。因此,在我的项目代码中,我将在cPanel中创建一个noreply@example2.com帐户,然后使用这个作为发送电子邮件地址的SwiftMailer API。

#3


2  

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.

如果您试图将消息发送到CPanel中的域,即使您的电子邮件托管在其他地方,它们的邮件服务器也会尝试将消息传递到本地邮箱,而不是查询该域的MX记录。

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.

解决方案是告诉他们在其exim邮件服务器配置文件中从本地主机选项中删除要发送的域。

#4


0  

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

使用这个主机上存在的有效电子邮件地址(假设它是example.com)——noreply@example.com。

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

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

#5


0  

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.

我正在使用SwiftMail for PHP和hostgator, Swift_SmtpTransport通过ssl连接到gmail。一开始,我得到一个“连接无法与主机smtp.gmail.com建立[连接被拒绝#111]”。使用Swift_MailTransport确实有用,但我不喜欢这种解决方案,因为它将使用hostgator的邮件服务器;我想用谷歌应用程序的邮箱账号发送邮件。

I had to ask HostGator's tech support to whitelist the cPanel user in the firewall for SMTP, and then everything worked well.

我不得不请求HostGator的技术支持在SMTP的防火墙中为cPanel用户添加白名单,然后一切都运行得很好。

#6


0  

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.

我在尝试使用Amazon的简单邮件服务发送电子邮件时犯了这个错误。最终证明我使用亚马逊的凭证是错误的。一旦我得到了正确的答案,所有的事情都为我解决了。

By the way I was using PHP's Swift_SmtpTransport

顺便说一下,我使用的是PHP的Swift_SmtpTransport

#1


13  

You can try using Swift_MailTransport instead of Swift_SmtpTransport which will use the native mail() call behind the scenes.

您可以尝试使用Swift_MailTransport,而不是使用本地mail()调用的Swift_SmtpTransport。

I have no experience with HostGator but if their support says the system allows sending through mail() this should work fine.

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

#2


4  

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

我做了一些测试,终于找到了答案。它确实有效,但以下是方法:

  • use port 25, not an alternative port
  • 使用端口25,而不是替代端口。
  • do not use SSL/TLS
  • 不使用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
  • 不要使用“localhost”——使用邮件帐户存在的域的名称,无论是根域、addon域、子域还是已停止的域
  • 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 noreply@example2.com account in cPanel and then use this as the sending email address with the SwiftMailer API.
  • 确保发送电子邮件帐户存在,并存在于您想要的域环境中。例如,我可能有example1.com作为根域,而example2.com作为我的项目的addon域。因此,在我的项目代码中,我将在cPanel中创建一个noreply@example2.com帐户,然后使用这个作为发送电子邮件地址的SwiftMailer API。

#3


2  

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.

如果您试图将消息发送到CPanel中的域,即使您的电子邮件托管在其他地方,它们的邮件服务器也会尝试将消息传递到本地邮箱,而不是查询该域的MX记录。

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.

解决方案是告诉他们在其exim邮件服务器配置文件中从本地主机选项中删除要发送的域。

#4


0  

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

使用这个主机上存在的有效电子邮件地址(假设它是example.com)——noreply@example.com。

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

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

#5


0  

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.

我正在使用SwiftMail for PHP和hostgator, Swift_SmtpTransport通过ssl连接到gmail。一开始,我得到一个“连接无法与主机smtp.gmail.com建立[连接被拒绝#111]”。使用Swift_MailTransport确实有用,但我不喜欢这种解决方案,因为它将使用hostgator的邮件服务器;我想用谷歌应用程序的邮箱账号发送邮件。

I had to ask HostGator's tech support to whitelist the cPanel user in the firewall for SMTP, and then everything worked well.

我不得不请求HostGator的技术支持在SMTP的防火墙中为cPanel用户添加白名单,然后一切都运行得很好。

#6


0  

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.

我在尝试使用Amazon的简单邮件服务发送电子邮件时犯了这个错误。最终证明我使用亚马逊的凭证是错误的。一旦我得到了正确的答案,所有的事情都为我解决了。

By the way I was using PHP's Swift_SmtpTransport

顺便说一下,我使用的是PHP的Swift_SmtpTransport