Sometimes if you are continuously sending emails from one email address to second email address.
Email server automatically forward it to spam after some attempts.
Also check mail function header contents like from name and from email.
This doesn't have much to do with the actual email sending code. Email receivers often place mails in a spam box in a testing phase, when sent emails don't really contain anything. When your emails contain real content, however, that is meant to provide information to a user, the chance of it reaching the user's inbox is much bigger. You could also tell your users that the mail _could_ end up in the spam folder, but often they're smart enough to figure that out themselves.