2016-04-06 24 views
6

Tôi cần tắt xác thực chứng chỉ ssl cho mục đích phát triển nhưng tôi không tìm thấy bất kỳ điều gì về điều này trong tài liệu chính thức. http://swiftmailer.org/docs/introduction.htmlSwiftMailer - PHP - Cách tắt xác thực chứng chỉ ssl

Tôi đang sử dụng php 5.6 và Symfony2 (v2.7).

Các tài liệu tham khảo cấu hình của SwiftMailerBundle là:

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

Kiểm tra https://github.com/swiftmailer/swiftmailer/issues/571. Bạn có thể cần phải nâng cấp Swift lên phiên bản mới nhất và làm theo hướng dẫn của họ ở đó. – apokryfos

Trả lời

2

Tôi nghĩ rằng đây là một bẩn hack nhưng nó làm việc cho tôi tốt;)

$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

Lấy swiftmailer.mailer.default.transport từ Symfony và thiết lập sau công trình cấu hình cho tôi:

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

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

Tôi không nghĩ rằng tôi có thể đặt tùy chọn luồng trong tệp .yml.

8

Tôi tìm thấy một tính năng không có giấy tờ

symfony 2.8, php 5.6, swiftmailer-bó 2.5.3

Swiftmailer Cấu hình

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

Cũng hoạt động với Symfony 3.3, Swiftmailer-bundle 3.1.6 và php 7.1 – Fuujin

+1

Tùy chọn không được công nhận "stream_options" trong "swiftmailer" với Symfony 3.3, Swiftmailer-bundle 3.1.6 và php 7.1 – alexeevyci

+0

Cũng hoạt động với Symfony 4.0.4 –

0

Các tùy chọn cấu hình đề nghị của Maxim không làm việc cho tôi (Symfony 3.4 và Swift Mailer 5.4)

Giải pháp sạch nhất mà tôi có thể tìm thấy như sau:

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

nơi $mailer là dụ SwiftMailer của bạn mà bạn sử dụng trong một số dịch vụ hoặc điều khiển

Các vấn đề liên quan