Swift_TransportException 无法与主机 smtp.gmail.com 建立连接
2022-08-30 16:08:56
我无法弄清楚我的生活究竟为什么它失败了。这是我得到的确切错误:
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
我使用的代码是我从教程中得到的,并阅读了这里的例子,这里是:
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);
非常感谢任何帮助,我已经阅读和搜索,找不到解决此:(
编辑:显然这是gmail的问题,我换了一个不同的smtp,它的工作原理。:S