The code is only sample, it is not fully functional.
It makes sense to create a small module and attach it to the hook.
Because when you update Prestashop, changes and modifications in Mail.php will be overwritten.
A good programmer can have a ready-made solution within a maximum of two hours 😉