Using WP_Mail on MacOS 12 (Monterey – M1) [closed]

Hi I put this function on the functions.php or in a plugin and works for me everywhere, on localhost or in any server. just need to change the strings to your email smtp settings. Only with gmail I could not make it work so far, all the other ones I try it works perfectly.

// Overriding wp smtp email to send smtp emails (no spam emails)
if (! function_exists('email_sender')){
 add_action('phpmailer_init','email_sender');
 function email_sender($mail){
     $mail->SetFrom('[email protected]', 'thenameIwant to appear on the emails sended');
     $mail->Host="smtp-mail.outlook.com";
     $mail->Port = 587;
     $mail->SMTPAuth = true;
     $mail->SMTPSecure="STARTTLS";
     $mail->Username="[email protected]";
     $mail->Password = 'mypassword';
     $mail->IsSMTP();
 }
}

then email should work like a charm! I normally use wp_mail() to do it.