Domanda

ho scaricato Swift Mailer dal loro sito e provare a inviare e-mail con semplice seguente codice

     <?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);

?>

Una volta ho eseguito nella pagina dà errore

      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

Se rimuovo la riga

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

quindi eseguire pagina e nessun display messaggio di errore, non appena aggiungo di sopra della linea di inviare e-mail, ho ottenuto l'errore.

il mio server in uscita, la porta e user id e password sono corretti nel mio file.

Grazie

È stato utile?

Soluzione

E 'cercando lo smtp.domain.org server, ma non è in grado di risolverlo.

Se si guarda la linea l'ultimo passo nel commercio pila sta chiamando, si può vedere che un'eccezione:

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 . ']'
    );
}

in modo che sia necessario inserire un server SMTP valido o avvolgere la linea di trasmissione () in un try / catch per intercettare l'eccezione e neanche il login da qualche parte o ignorarla

Altri suggerimenti

Gli errori si dicono tutto quello che dovete sapere:

getaddrinfo failed: No such host is known.

Il server SMTP specificato (smtp.domain.org) non esiste, quindi lo script mailer non può connec ad esso per inviare l'e-mail. Almeno il dominio domain.org esiste, quindi forse hanno avuto il server SMTP denominato qualcos'altro:

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.

Specifica qualche altro host SMTP che esiste e riprovare.

Si prega di controllare se la porta si utilizza è davvero la porta utilizzata dal server di posta. Ho affrontato un problema simile e alla fine ho visto che stavo usando la porta 25 con Yahoo, invece di 465.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top