S
S
svsova2020-05-25 18:40:46
PHP
svsova, 2020-05-25 18:40:46

How to connect to Yandex SMTP?

Hello! I can't send mail via PHPMailer, yesterday I spent the whole day on this question.
Maybe I'm missing some small thing. I will be grateful for any help.

What I've done:

  1. In his account, yandex created and confirmed the domain mydomain.ru
  2. Registered mx.yandex.ru in the records
  3. Created mail [email protected] (to send service messages registration, recovery ...)
  4. Sending via PHPMailer 6.1.5
  5. I thought the login and password were not correct, I went through all the combinations.
  6. Created a separate password for the application, did not help
  7. Tried different port settings and ENCRYPTION_xxx


I took the code example from the source

How to configure these parameters correctly?

//Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;		// Enable verbose debug output
    $mail->isSMTP();							// Send using SMTP
    $mail->Host       = 'smtp.yandex.ru';		// Set the SMTP server to send through
    $mail->SMTPAuth   = true;					// Enable SMTP authentication

  $mail->Username   = 'логин аккаунта без @yandex.ru';			// SMTP username
  $mail->Password   = 'пароль аккаунта';		// SMTP password
    
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;	// Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port       = 465;					// TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above


Depending on the settings, I get 2 types of errors
2020-05-25 15:29:38 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

или 

2020-05-25 15:39:14 SERVER -> CLIENT:
2020-05-25 15:39:14 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
svsova, 2020-05-27
@svsova

Technical support solved the issue in 2 approaches. Here it is in short.

When analyzing the problem, we found that the server had outdated root certificates, as a result of which the SSL connection to Yandex mail servers ended with an error, for example:

[[email protected] /]# echo | openssl s_client -servername smtp.yandex.ru -connect smtp.yandex.ru:465 2>&1 | grep 'Verify return code'
Verify return code: 20 (unable to get local issuer certificate)
[[email protected] /]#

Added the Yandex root certificate to the list of trusted certificates on the server. Now we do not see any problems with a secure connection to their mail servers:

[[email protected] /]# echo | openssl s_client -servername smtp.yandex.ru -connect smtp.yandex.ru:465 2>&1 | grep 'Verify return code'
Verify return code: 0 (ok)
[[email protected] /]#

My
error has changed a little.
Before 2020-05-25
19:59:25 SMTP ERROR: Failed to connect to server: (0) Now
2020-05-26
20:52:58 SMTP ERROR: Failed to connect to server: Connection refused (111)
Stage 2 TP:
We made additional settings for root certificates and specified a host for connection in the SMTP script.

Here's what the test script throws out when sending a letter successfully.
5ece0e271aa20037306272.jpeg
How it works for me.
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host       = 'smtp.yandex.ru';
$mail->SMTPAuth   = true;
$mail->Username   = '[email protected]';	
$mail->Password   = 'пароль от ящика [email protected]';
    
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port       = 465;

Yes, another useful service to check your settings https://www.smtper.net/ and understand that the matter is in hosting and not in your head))
PS here you can also check the connection in PHP
var_dump(fsockopen("ssl://smtp.yandex.ru",465));

результат 
resource(2) of type (stream)

если подключения нет пишет
bool(false)

Thanks to everyone who responded!!!

L
Lone Ice, 2020-05-26
@daemonhk

The most banal - did you go to your mailbox through Yandex.Mail? Has it been confirmed?

A
Anton, 2020-05-26
@anton99zel

account login without yandex.ru

mail for the domain - you need to specify the mailbox in full
===
you need to use Open SSL in php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question