質問

私は彼らのウェブサイトからSwiftMailerをダウンロードし、次のコードで簡単な電子メールを送信しようとしました

     <?php
     require_once 'lib/swift_required.php';

    $transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
    ->setUsername('your username')
     ->setPassword('your password')
      ;


    $mailer = Swift_Mailer::newInstance($transport);

  //Create a message
  $message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
 ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
 ->setBody('Here is the message itself')
 ;

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

?>

ページを実行すると、エラーが発生します

      Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php  on line 233

    Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.anyhost.com:25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php on line 233

   Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.domain.com [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]' in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php:235 Stack trace: #0 E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php(70): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 E:\web_sites\swift_mail\lib\classes\Swift\Transport\AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 E:\web_sites\swift_mail\lib\classes\Swift\Mailer.php(74): Swift_Transport_AbstractSmtpTransport->start() #3 E:\web_sites\swift_mail\test.php(33): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php on line 235

線を削除した場合

  $result = $mailer->send($message);

次に、ページを実行してエラーメッセージ表示なしで、電子メールを送信するために上記の行を追加するとすぐに、エラーが発生しました。

私の送信サーバー、ポート、ユーザーID&パスワードは私のファイルで正しいです。

ありがとう

役に立ちましたか?

解決

サーバーSMTP.domain.orgを探していますが、解決することはできません。

Stack Tradeの最後のステップが呼び出しているというラインを見ると、例外を投げているのがわかります。

if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
{
  throw new Swift_TransportException(
    'Connection could not be established with host ' . $this->_params['host'] .
    ' [' . $errstr . ' #' . $errno . ']'
    );
}

したがって、有効なsmtpサーバーを入力するか、send()行をトライ/キャッチでラップして例外をキャッチする必要があります。

他のヒント

エラーは、あなたが知る必要があるすべてをあなたに教えてくれます:

getaddrinfo failed: No such host is known.

指定されたSMTPサーバー(smtp.domain.org)は存在しないため、メーラースクリプトは電子メールを送信するために接続できません。少なくともdomain.orgドメインは存在しているので、おそらく彼らは他の何かという名前のSMTPサーバーを持っている:

marc@panic:~$ host -t soa domain.org
domain.org has SOA record ns.domain.org. sales.domain.org. 1267596439 10800 3600 604800 3600
marc@panic:~$ host -t mx domain.org
domain.org mail is handled by 10 mail.domain.org.
marc@panic:~$ host domain.org
domain.org has address 208.109.97.130
domain.org mail is handled by 10 mail.domain.org.

存在する他のSMTPホストを指定し、再試行します。

使用するポートが実際にメールサーバーが使用するポートであるかどうかを制御してください。私は同様の問題に対処しましたが、ついに465ではなくYahooでポート25を使用していることがわかりました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top