Domanda

Ecco il mio codice PHP:

function SendCookieToTheMail()
{
    require_once 'swift-mailer/lib/swift_required.php';
    //Create the Transport
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
      ->setPort(465)
      ->setEncryption('ssl')
      ->setUsername('007@gmail.com')
      ->setPassword('123')
      ;

    //Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);

    //Create a message
    $message = Swift_Message::newInstance('Test')
      ->setFrom(array('007@gmail.com' => 'From mr. 007'))
      ->setTo(array('007@gmail.com', '007@gmail.com' => 'To mr. 007'))
      ->setBody('Body')
      ;

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

    /*
    You can alternatively use batchSend() to send the message

    $result = $mailer->batchSend($message);
    */ 
}

Ecco l'errore:

( ! ) Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\Program Files\wamp\www\swift-mailer\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.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #44551400]' in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235

( ! ) Swift_TransportException: Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #44551400] in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235

Dov'è il problema ??

Aggiorna:

Ho controllato phpinfo() e dice:

OpenSSL support     disabled (install ext/openssl) 

Ho fatto riferimento ai collegamenti seguenti, ma non sono riuscito a installare ssl ...

È stato utile?

Soluzione

Il tuo php supportava SSL? http://php.net/manual/en/function.fsockopen.php e controlla http://www.php.net/manual/en/openssl.installation.php come riferimento.

Crea una pagina con

phpinfo();

SSL è abilitato?

Altri suggerimenti

Stavo cercando una domanda simile e ho scoperto che devi modificare il file php.ini modifica la riga seguente

;extension=php_openssl.dll

rimuovi il punto e virgola e funzionerà correttamente

Spero che questo aiuti chiunque altro :)

gmail ne ha bisogno nel tuo config.yml

swiftmailer: crittografia: tls

o sostituisci il tuo: -> setEncryption ('ssl') di -> setEncryption ('tls')

e non ssl

Dovresti abilitare il modulo php_openssl dalle estensioni php.Modifica il tuo file php.ini

extension=php_openssl.dll

infatti, consiglio di usare tls sulla porta 25 test utilizzando la seguente sintassi:

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25, 'tls')
    ->setUsername('007@gmail.com')
    ->setPassword('123');

Devi configurare php per lavorare con ssl

http://www.php.net/manual/en/openssl.installation.php

Spero che tu abbia risolto il tuo problema, tuttavia per me riga:

;extension=php_openssl.dll

non esisteva nel mio php.ini (eseguendo XAMPP 1.7.7 su Win7), quindi vai avanti e aggiungilo nella sezione delle estensioni, rimuovi il punto e virgola da esso e dovrebbe funzionare.

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