In short, WhatsApp’s design doesn’t allow automatic message sending without user interaction, ensuring user privacy and preventing spam.
All what your code would do, is to open a whatsapp-browser-window with prefilled message text. An automatic sending of the message would not work. It would need a user-interaction → like a button confirmation-click.
But what would work is —> if you would have the WhattsApp-Business-Package, or using Twilio.
You can test this WHATTSAPP-LINK (entering your own phone-number) → replacing the → 1111111111111111
Before using the shown link → make sure that WHATSAPP is installed on your device.