Contact form – problem with displaying message about sent mail

I understand your hesitation about using 3rd party plugins, but form handling is a primary candidate to offload to one. That’s coming from someone who always tries to build bespoke.

There is a reason why several well-established WP form plugins exist – forms are tedious to build & handle manually, prone to errors & unwittingly introducing security vulnerabilities. There are so many elements to consider & cater for.

If you still wish to pursue your own form building, I would strongly suggest using an existing PHP framework or library (I can’t recommend one personally but you can check out a bunch on packagist).

It’ll mean you can code your forms more expressively & less verbosely, focusing on what the form is rather than dealing with all the repetitive & tedious mechanics of standard form processing.