2016-04-06 30 views
6

Devo disattivare la convalida del certificato ssl per scopi di sviluppo ma non trovo nulla a riguardo nella documentazione ufficiale. http://swiftmailer.org/docs/introduction.htmlSwiftMailer - PHP - Come disabilitare la convalida del certificato ssl

Sto utilizzando php 5.6 e Symfony2 (v2.7).

Il riferimento configurazione del SwiftmailerBundle è:

swiftmailer: 
    transport:   smtp 
    username:    ~ 
    password:    ~ 
    host:     localhost 
    port:     false 
    encryption:   ~ 
    auth_mode:   ~ 
    spool: 
     type:     file 
     path:     '%kernel.cache_dir%/swiftmailer/spool' 
    sender_address:  ~ 
    antiflood: 
     threshold:   99 
     sleep:    0 
    delivery_address:  ~ 
    disable_delivery:  ~ 
    logging:    '%kernel.debug%' 
+1

Controllare https://github.com/swiftmailer/swiftmailer/issues/571. Probabilmente è necessario aggiornare Swift alla versione più recente e seguire le loro istruzioni lì. – apokryfos

risposta

2

penso che questo è un hack sporco, ma per me funziona benissimo;)

$https['ssl']['verify_peer'] = FALSE; 
$https['ssl']['verify_peer_name'] = FALSE; // seems to work fine without this line so far 
/** @var \Swift_Transport_EsmtpTransport $transport */ 
$transport = $this->get('swiftmailer.mailer.default.transport'); 
$transport->setStreamOptions($https); 
1

Ottenere il swiftmailer.mailer.default.transport da Symfony e di impostazione in seguito a lavori di configurazione per me:

$transport = $this->get("swiftmailer.mailer.default.transport"); 

// disable SSL certificate validation 
$transport->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false))); 

Non penso che sia io È possibile impostare le opzioni di streaming nel file .yml.

8

Ho trovato una funzionalità non documentata

symfony 2.8, PHP 5.6, swiftmailer-fascio 2.5.3

configurazione Swiftmailer

swiftmailer: 
    stream_options: 
    ssl: 
     verify_peer: false 
     verify_peer_name: false 
+1

Funziona anche con Symfony 3.3, Swiftmailer-bundle 3.1.6 e php 7.1 – Fuujin

+1

Opzione non riconosciuta "stream_options" in "swiftmailer" con Symfony 3.3, Swiftmailer-bundle 3.1.6 e php 7.1 – alexeevyci

+0

Funziona anche con Symfony 4.0.4 –

0

L'opzione di configurazione suggerita da Maxim non ha funzionato per me (Symfony 3.4 e Swift Mailer 5.4)

La soluzione più pulita che ho trovato è la seguente:

$transport = $mailer->getTransport(); 
if($transport instanceof \Swift_Transport_EsmtpTransport){ 
    $transport->setStreamOptions([ 
     'ssl' => ['allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false] 
    ]); 
} 

dove $mailer è l'istanza SwiftMailer che si utilizza in qualche servizio o il controller