M
M
Michael Aniskin2020-05-29 19:53:52
PHP
Michael Aniskin, 2020-05-29 19:53:52

SMTP PHP yandex.ru The password was not accepted by the server as correct! How to fix?

I'm trying to build a script to send emails.
part of the script....

fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
  if (!server_parse($socket, "334", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Логин авторизации не был принят сервером!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket,base64_encode($config['smtp_password']). "\r\n");
  if (!server_parse($socket, "235", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Пароль не был принят сервером как верный! Ошибка авторизации!</p>';
    fclose($socket);
    return false;
  }
  fputs($socket, "MAIL FROM: <".$config['smtp_username'].">\r\n");
  if (!server_parse($socket, "250", __LINE__)) {
    if ($config['smtp_debug']) echo '<p>Не могу отправить комманду MAIL FROM: </p>';
    fclose($socket);
    return false;
  }
.......
function server_parse($socket, $response, $line = __LINE__) {
  global $config;
  while (@substr($server_response, 3, 1) != ' ') {
    if (!($server_response = fgets($socket, 256))) {
      if ($config['smtp_debug']) echo "<p>Проблемы с отправкой почты!</p>$response<br>$line<br>";
 			return false;
 		}
  }
  if (!(substr($server_response, 0, 3) == $response)) {
    if ($config['smtp_debug']) echo "<p>Проблемы с отправкой почты!</p>$response<br>$line<br>";
    return false;
  }
  return true;
  
}

I met this script in many places, and there is nowhere to get lost. But it gives the error
'Problems sending mail! 235 52 The password was not accepted by the server as correct! Authorisation Error!
I tried the mailbox and Yandex, the result is the same. At the same time, the steps before it are executed without errors. What am I messing with???

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Igor Makhov, 2020-05-30
@MichaelAniskin

Try turning off app passwords in your profile settings. I had a similar problem: no imap/smtp client connected.

B
brar, 2020-05-29
@brar

Perhaps yandex blocked login attempts. They do this sometimes, forcing them to bind a phone number. You need to go through the web and confirm, a confirmation code will come to your phone.
I don’t specifically remember the link (it came in my smpt server response, something like ya.cc/blablabla ).
Well, or the second option is to try using another mailbox that definitely works in the mail client.
Naturally, this is not the only variant of your problem.
Also try just a script:

<?php
require_once ( '/usr/share/php/libphp-phpmailer/autoload.php' ); // Убедитесь в этом пути.

//$mail = new PHPMailer;
$mail = new PHPMailer\PHPMailer\PHPMailer();

//Enable SMTP debugging. 
$mail->SMTPDebug = 3;                               
//Set PHPMailer to use SMTP.
$mail->isSMTP();            
//Set SMTP host name                          
$mail->Host = "smtp.yandex.ru";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                          
//Provide username and password     
$mail->Username = "ВАШ_ЯЩИК";                 
$mail->Password = "ВАШ_ПАРОЛЬ";                           

$mail->SMTPSecure = "ssl";                           
//Set TCP port to connect to 
$mail->Port = 465;                                   
$mail->From = "ВАШ_ЯЩИК";
$mail->FromName = "пофигу_что_тут";
$mail->addAddress("ЯЩИК_АДРЕСАТА");
$mail->isHTML(true);
$mail->Subject = "Test MAIL 1";
$mail->Body = "<i>from сonsole</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

You need to make sure PHPMailer is installed.
The script is completely working, I just checked it.

O
Oleg, 2020-05-30
@402d

It's easier to persuade Google mail to accept mail directly (it's enough to put a guard that non-secure logins are allowed) than mailra with Yandex.
For them, you will also have to configure SPF and DKIM.

Y
Yakov, 2020-06-04
Svetsky @jamessvetsky

To the subject of the question:
https://7fk.ru/nastroyka-smtp/
I just mentioned mail on Yandex, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question