Your code contains several security flaws that can and will bite newbies copying the code on their servers.
- you omit
htmlspecialchars → XSS
- the form is not protected against Cross Site Request Forgery
- user input is pasted unchecked in the mail’s headers → an attacker could easily send email to other adresses
- there are libraries for sending email: PHPMailer, SwiftMailer
There is no reason for implementing such thing by yourself.
Your code contains several security flaws that can and will bite newbies copying the code on their servers.
htmlspecialchars→ XSSThere is no reason for implementing such thing by yourself.