我不爲我到底爲什麼會失敗的生活..這是我得到確切的錯誤:Swift_TransportException連接無法與主機smtp.gmail.com建立
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 protected]')
->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('[email protected]' => 'no-reply'))
// Set the To addresses with an associative array
->setTo('[email protected]')
// 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
看起來一切(代碼明智)設置是否正確,您是否嘗試通過您在此處使用的登錄信息登錄Google Apps?如果您剛剛創建了該帳戶,那麼gmail會要求您在帳戶可以使用之前同意一些條款。在該頁面上點擊「同意」之前,對SMTP的訪問將不可用。 – SamT
是的,我有該電子郵件目前正在工作。 – Andres
您的服務器是否允許通過465端口進行SSL連接?我知道一些共享主機,禁用此功能。如果是這種情況,通常您只需聯繫支持人員,他們將爲您開放該端口。 – Julien