Spam problem for the following reasons
1) Shared hosting
If you use shared hosting, PHP is not a solution to this problem. Try contacting your server providers. Sometimes your IP address is considered spam. Try changing your hosting providers. It may work fine.
2) Additional links in your body of the letter
3) Partial Header (Always Use Answer-On, Ref Ans: TrentonMcManus)
4) Bulk Email
5) Spam report (the number of people who clicked on your link as spam)
6) The message should not be too short or too long.
7) Sending from the black list (hosting and SMTP server))
Perhaps your new IP address was previously blacklisted by Google or Hotmail. You can check Blacklisted ip or not from the site here.
8) IP Sender Verification
The Sender Policy Framework (SPF) is an email authentication system designed to prevent email spam by detecting email spoofing, a common vulnerability, by checking the sender's IP addresses.
PHP may not be the solution to this. You can do the following in php encoding
1) Always use the from / reply to address parameter
2) Add unsubscribe link in the body
3) Avoid spam.
4) The message should not be too short or too long.
5) The text version is better than HTML
Abdul majeed
source share