27

なぜそれが失敗しているのか、私は一生理解できません。これは私が得ている正確なエラーです。

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が使用しているコードは、チュートリアルとここでの例を読んで得たものです。ここにあります。

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

4

13 に答える 13

20

致命的なエラー:「ホスト smtp.gmail.com との接続を確立できませんでした [接続が拒否されました #111]」というメッセージを含むキャッチされない例外「Swift_TransportException」

接続が拒否されました は、非常に明確で明確なエラー メッセージです。これは、リモート エンドがアクティブに接続を拒否したため、ソケット接続を確立できなかったことを意味します。

Google が接続をブロックしている可能性はほとんどありません。

Web ホスティング プロバイダーのファイアウォール設定がポート 465 での送信接続をブロックしているか、SMTP から Gmail をブロックしている可能性が非常に高くなります。465 はセキュア SMTP の「間違った」ポートですが、よく使用され、Gmail はそこでリッスンします。代わりにポート 587 を試してください。それでも接続が拒否される場合は、ホストに電話して状況を尋ねてください。

于 2013-01-06T03:48:43.947 に答える
7

config.yml から削除します spool: { type: memory }

次に、このようにtry catchを追加します

    try{
        $mailer = $this->getMailer();
        $response = $this->getMailer()->send($message);
    }catch(\Swift_TransportException $e){
        $response = $e->getMessage() ;
    }
于 2014-02-20T20:17:07.650 に答える
1

同じ問題があり、AVAST Anti Virus を無効にすることで問題を解決できました。ブラウザの私のAVAST拡張機能と同様に。ウイルス対策がアプリケーションをブロックすることがあります。:) 誰にでも役立つことを願っています。

于 2017-10-25T11:21:22.680 に答える
0

私の場合、Laravel 5 を使用していましたが、ディレクトリのルート フォルダーにある .env ファイルのメール グローバルを変更するのを忘れていました (これらの変数はメール構成を上書きします)。

   MAIL_DRIVER=smtp
   MAIL_HOST=smtp.gmail.com
   MAIL_PORT=465
   MAIL_USERNAME=yourmail@gmail.com
   MAIL_PASSWORD=yourpassword

デフォルトでは、メールホストは次のとおりです。

   MAIL_HOST=mailtraper.io

同じエラーが発生していましたが、うまくいきました。

于 2015-04-26T23:49:36.157 に答える