[英]HostGator Won't Send Mail via PHP SwiftMail API
Is there a reason why SwiftMail API for PHP won't run on HostGator? 有没有理由为什么SwiftMail API for PHP不能在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.
他们的技术支持说使用mail()命令,并且到端口25的套接字连接不会像他们的共享主机方案那样工作。 I complained and said that when you google on how to send attachments with mail(), people tell you to use SwiftMail.
我抱怨说,当你谷歌如何发送邮件附件(),人们告诉你使用SwiftMail。 I need to send file attachments with the email.
我需要通过电子邮件发送文件附件。
My code works just fine on A2Hosting, but not HostGator. 我的代码在A2Hosting上运行得很好,但不是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.
在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上工作,请分享您的所作所为。
You can try using Swift_MailTransport
instead of Swift_SmtpTransport
which will use the native mail()
call behind the scenes. 您可以尝试使用
Swift_MailTransport
而不是Swift_SmtpTransport
,它将在幕后使用本机mail()
调用。
I have no experience with HostGator but if their support says the system allows sending through mail()
this should work fine. 我没有使用HostGator的经验,但如果他们的支持说系统允许通过
mail()
发送,这应该可以正常工作。
I ran some tests and found the answer finally. 我做了一些测试,最后找到了答案。 It does work, but here's how:
它确实有效,但这是如何:
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邮件服务器配置文件中的localhost选项中删除您尝试通过电子邮件发送的域。
I am using SwiftMail for PHP with hostgator with Swift_SmtpTransport connecting to gmail over ssl. 我正在使用SwiftMail for PHP与hostgator一起使用Swift_SmtpTransport通过ssl连接到gmail。 At first I was getting a "Connection could not be established with host smtp.gmail.com [Connection refused #111]".
起初我得到了“连接无法与主机smtp.gmail.com建立[连接拒绝#111]”。 Using Swift_MailTransport did work, but I did not like that solution because it would use hostgator's mail server;
使用Swift_MailTransport确实有效,但我不喜欢这个解决方案,因为它会使用hostgator的邮件服务器; 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. 我不得不要求HostGator的技术支持将防火墙中的cPanel用户列入白名单,然后一切运行良好。
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.
最终它证明了我使用AmazonSES的凭据是错误的。 Once i got this correct every thing resolved out for me.
一旦我得到了这个正确的解决方案。
By the way I was using PHP's Swift_SmtpTransport 顺便说一句,我使用PHP的Swift_SmtpTransport
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记录吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.