php-swiftmailerHow to ignore a certificate when using Swiftmailer?
Swiftmailer provides a way to ignore a certificate when using it. To do this, you need to set the stream_options
parameter to ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]
when creating the transport instance.
Example code
$transport = (new Swift_SmtpTransport('smtp.example.org', 465, 'ssl'))
->setStreamOptions(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]);
Code explanation
Swift_SmtpTransport
: This is the class used to create the transport instance.smtp.example.org
: This is the hostname of the SMTP server.465
: This is the port used for the SMTP server.ssl
: This is the encryption protocol used for the SMTP server.setStreamOptions
: This is the method used to set thestream_options
parameter.['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]
: This is the value of thestream_options
parameter, which is used to ignore the certificate.
Helpful links
More of Php Swiftmailer
- How to log emails sent with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to configure Swiftmailer for SMTP without authentication?
- Swiftmailer usage example
- How to send emails in UTF8 using Swiftmailer?
- How to set timeout with Swiftmailer?
- How to use Swiftmailer transport?
- How to set the 'from' address in Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
See more codes...