Mail sent by mail function marked as spam
There are too many variables to fully eliminate this. The problem that you face is that today's email filters are very efficient at their job. One of the shortcomings of course is that sometimes they filter out email which is not spam. That having been said, it's quite subjective - you might think that the email your site is sending out to someone is critical, but I might not. I'd probably consider it spam, depending upon its contents.
It depends upon the content of your email (text vs HTML, sensitive words like "unsubscribe"), the server upon which the site is hosted, and the destination of the mail. Unfortunately, there's little you can do in terms of guaranteeing delivery to their inbox (rather than spam folder), which is why most sites add a caveat these days, warning users to check their spam folders.
Issue delivering email to hotmail inbox?
There is not much you can do from your PHP code. However your code seems to be ok.
Double check your SPF records in DNS. You can read more about SPF records here.
Also consider using Domain Keys
Related Topics
Swap Two Words in a String PHP
Using PHP Include to Separate Site Content
Check If Http Request Comes from My Android App
Imagick Not Loading Images, with 'Nodecodedelegateforthisimageformat' Error Message
Make Text Between Asterisks Bold
PHP Mail() Works from Command Line But Not Apache
Find All Hrefs in Page and Replace with Link Maintaining Previous Link - PHP
Strip HTML Tags and Its Contents
More Efficient Hierarchy System
Why Is the Semicolon Optional in the Last Statement in PHP
Htaccess Rule to Parse PHP in HTML Files Not Working
How to Use MySQLi_Fetch_Object with a Prepared Statement
Simple PHP Mail Function Not Working on Amazon Server Ec2
How to Put a Translation System in PHP Website
Ssl Error Can Not Change to Tls
Extending Session Timeout in PHP via the .Htaccess