H
H
HexUserHex2021-11-07 13:54:46
PHP
HexUserHex, 2021-11-07 13:54:46

Why doesn't sending mail from PHPMailer using smtp.yandex work?

Good afternoon,

I’m trying to send myself a test message using the yandex SMTP server, I sketched out such an example, but as a result of the letter I still don’t receive any errors during its execution.

there are two php.ini configs on the server:

/etc/php/7.3/apache2/php.ini
/etc/php/7.3/cli/php.ini


In both configs, I specified the smtp server and port from the Yandex off page:
SMTP = smtp.yandex.ru
and
smtp_port = 465

I installed phpmailer myself using composer:
composer require phpmailer/phpmailer

Script example:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer;

$mailToAddr = '[email protected]';
$subject = 'test';
$message = 'message';

try {
  $mail->IsSMTP();                                                            // Set mailer to use SMTP
  $mail->Host = 'smtp.yandex.ru';                                     // Specify main and backup server
  $mail->Port = 465;                                                         // Set the SMTP port
  $mail->SMTPAuth = true;                                               // Enable SMTP authentication
  $mail->Username = '[email protected]';                // SMTP username
  $mail->Password = 'nerabotayouposng';                        // SMTP passwora
  $mail->SMTPSecure = 'ssl';                                            // Enable encryption, 'ssl' also accepted                                                                                            

  $mail->From = '[email protected]';
  $mail->FromName = 'TEST';
  $mail->AddAddress($mailToAddr, 'test');

  $mail->Subject = $subject;
  $mail->Body = $message;

  $mail->Send()

} catch(phpmailerException $e) {
  echo $e->errorMessage();
}

?>


Before starting, I completely clear the syslog, then I run my script and after 2-3 minutes in the logs I see:
Nov  7 13:39:01 vm274093 CRON[22718]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Nov  7 13:39:01 vm274093 systemd[1]: Starting Clean php session files...
Nov  7 13:39:01 vm274093 systemd[1]: phpsessionclean.service: Succeeded.
Nov  7 13:39:01 vm274093 systemd[1]: Started Clean php session files.
Nov  7 13:40:01 vm274093 CRON[22922]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)


As far as I understand, syslog does not send messages instantly, but 'collects them for further sending in batches'?
In general, there are no errors in the logs ...

Tell me what could be wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Roo, 2021-11-07
@HexUserHex

Yandex requires a separate password for "mail programs"

O
Oleg, 2021-11-07
@402d

because the spammers got everyone and now setting up a mailing list is not just a few lines in PHP.
SPF, DKIM and DMARC - read what it is.
well, most mailers do not like plain authorization

T
TheAndrey7, 2021-11-07
@TheAndrey7

You have the same sender and recipient address, so maybe that's why he doesn't want to send to himself. Otherwise, the SMTP server should return an error.
Using Yandex is not the best idea; setting up your own server is not so difficult. If you fit into the limits , then for now you can use it.

T
ThunderCat, 2021-11-07
@ThunderCat

$mail->SMTPDebug = 3; and watch what is happening, all that is written here is poking a finger into the sky. Why no one said that it is necessary to understand what the problem is, instead of putting forward strange unreasonable assumptions, is a mystery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question