Email always ends up in spam

There are a wide variety of things this could be, so any answers to this question would be speculation. Keep in mind, it’s the email that gets marked as spam (and the details of the sender, domain, etc), not the code that generates the email.

That being said, I would investigate the sender information first to make sure the headers in the email are set to show the email is sent via a valid email address with the a domain that matches the sender’s domain or is authorized to send on behalf of the domain.

You can try a testing service like MXToolbox to ensure email is being delivered successfully.