热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

HostGator不会通过PHPSwiftMailAPI发送邮件-HostGatorWon'tSendMailviaPHPSwiftMailAPI

IsthereareasonwhySwiftMailAPIforPHPwontrunonHostGator?Theirtechsupportsaidusethe

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


推荐阅读
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
author-avatar
翟峰
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有