无法与主机smtp.gmail.com建立Swift_TransportException连接 [英] Swift_TransportException Connection could not be established with host smtp.gmail.com

查看:85
本文介绍了无法与主机smtp.gmail.com建立Swift_TransportException连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚我的一生为什么会失败.这是我得到的确切错误:

I can't figure for the life of me why exactly is it failing.. this is the exact error I am getting:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection  
could not be established with host smtp.gmail.com [Connection refused #111]' in 
/home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php:259 
Stack trace: #0 
/home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php(64): 
Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/content/38/6896038/html/test/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/content/38/6896038/html/test/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 /home/content/38/6896038/html/test/contact.php(55): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php on line 259

Im使用的代码是我从教程中读取的示例,这里是:

And the code Im using is what I've gotten from the tutorial and reading on here examples, here it is:

require_once 'lib/swift_required.php';

$transport = Swift_MailTransport::newInstance();

// Create the Transport the call setUsername() and setPassword()
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('email@googleappsdomain.com')
  ->setPassword('xxx')
  ;

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

$nombre = $_POST['name'];
$apellido = $_POST['apellido'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$title = $_POST['jobtitle'];

// Create the message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject('Nuevo applicante para: ' . $title)

  // Set the From address with an associative array
  ->setFrom(array('no-reply@topytop.com.pe' => 'no-reply'))

  // Set the To addresses with an associative array
  ->setTo('email@thisemail.com')

  // Give it a body
  ->setBody('<html>
                <head></head>
                <body>
                    <table>
                        <tr>
                            <td>Nombre:</td><td>' . $nombre . ' ' . $apellido .'</td>
                        </tr>
                        <tr>
                            <td>Email:</td><td>' . $email . '</td>
                        </tr>
                        <tr>
                            <td>Telefono:</td><td>'. $telefono .'</td>
                        </tr>
                    </table>
                </body>
            </html>', 'text/html')

  // Optionally add any attachments
  ->attach(Swift_Attachment::fromPath($_FILES["file"]["tmp_name"])->setFilename($_FILES['file']['name']));

// Send the message
$result = $mailer->send($message);

非常感谢您的帮助,我已经完成了阅读和搜索的工作,无法找到解决方案:(

any help is greatly appreciated, I've done my reading and searching and cannot find a solution to this :(

显然这是gmail的问题,我更改为其他smtp并成功了..:S

Apparently it's an issue with gmail, I changed to a different smtp and it worked.. :S

推荐答案

致命错误:消息连接无法与主机smtp.gmail.com建立未捕获的异常'Swift_TransportException'[拒绝连接#111]

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Connection refused #111]

拒绝连接是非常明确的错误消息.这意味着无法建立套接字连接,因为远端主动拒绝连接.

Connection refused is a very explicit and clear error message. It means that the socket connection could not be established because the remote end actively refused to connect.

Google不太可能阻止连接.

It's very unlikely that Google is blocking the connection.

您的网络托管服务提供商很可能具有防火墙设置,这些设置阻止了端口465上的传出连接,或者它们阻止了SMTP到Gmail的连接. 465是安全SMTP的错误"端口,尽管它经常被使用,并且Gmail确实在其中侦听.尝试改用端口587.如果仍然拒绝连接,请致电您的主机并询问他们怎么了.

It's very likely that your web hosting provider has firewall settings that block outgoing connections on port 465, or that they are blocking SMTP to Gmail. 465 is the "wrong" port for secure SMTP, though it is often used, and Gmail does listen there. Try port 587 instead. If the connection is still refused, call your host and ask them what's up.

这篇关于无法与主机smtp.gmail.com建立Swift_TransportException连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆