Trying to send mails from a php script with PHPMailer and using outlook / SMTP

I’m currently working on a script in php for sending emails via outlook SMTP .
I am using PHPMailer

exemple :

use PHPMailerPHPMailerPHPMailer;

require './vendor/autoload.php';
$mail = new PHPMailer(true);
try {
    $mail->isSMTP();
    $mail->Host = "smtp.live.com"; // smtp.office365.com doesn't work as well
    $mail->SMTPAuth = true;
    $mail->Username = "myoutlook365Email";
    $mail->Password = "xxx";
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587; 
    $mail->setFrom('myoutlook365Email', 'My name');
    $mail->addAddress('[email protected]', 'test');
    $mail->isHTML(true);
    $mail->Subject = 'Subject';
    $mail->Body = 'Body';
    $mail->AltBody = 'AltBody';

    $mail->send();

} catch (Exception $e) {
    echo 'Can't send.' . $mail->ErrorInfo;

The error : SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server SMTP code: 10060 Additional SMTP info

When I try with google and gmail smtp / email the error :
SMTP Error: Could not authenticate.

I’m sure this is the good password and email. I tried to allow less secure apps but it is not available anymore.

What can I do ?
Am I doing something wrong ?

I tried to send mail with Outlook SMTP. But it always result in an error