symfony: Mailer Transports to SMTP Cannot Establish Secure Connections
Symfony version(s) affected: 5.0.1
Description
When using the Transport out of the box, the Transport is unable to establish a secure connection. This issue looks similar to https://github.com/symfony/symfony/issues/34064
I am using OpenSSL 1.1.1d and PHP 7.4. I’ve reproduced the issue on PHP 7.3 as well.
The exact error message I receive is:
Connection could not be established with host "ssl://smtp.postmarkapp.com:587": stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number
How to reproduce
$transport = new PostmarkSmtpTransport($key);
$mailer = new Mailer($transport);
$mail = (new Email)->to('test@example.com')
->from('test@example.com')
->subject('Test Email')
->html('Test Email');
$mailer->send($mail);
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 15 (3 by maintainers)
Commits related to this issue
- bug #35518 [Mailer] Fix STARTTLS support for Postmark and Mandrill (fabpot) This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Fix STARTTLS support for Postmark and Mandrill | ... — committed to symfony/symfony by fabpot 4 years ago
- Remove TLS flag from Mailer instantiation This will make the mailer "auto-discover" the encryption capabilities of the SMTP server, allowing us to use port 587 with STARTTLS negotiation. Another solu... — committed to wmde/fundraising-application by gbirke 3 years ago
- bug #53061 [Mailer] [Mailjet] Disable tls for mailjet as it should use STARTTLS (RFreij) This PR was merged into the 6.4 branch. Discussion ---------- [Mailer] [Mailjet] Disable tls for mailjet as ... — committed to symfony/symfony by nicolas-grekas 6 months ago
To be clear, you should use
465, trueto use SSL to connect or587, falseto connect withou SSL and upgrade via STARTTLS. Any other combination won’t work. The code was buggy, fixing it here:I applied the patch in #34760 without success in resolving this bug.
MAIL_MAILER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=587 MAIL_USERNAME=myuser MAIL_PASSWORD=mypass MAIL_ENCRYPTION=STARTTLS
When I set env values like this, there is no error. but email not send to target email.
@hanzallahmsd did you try
MAIL_ENCRYPTION=starttls