Mails sent from code can go to spam for various reasons
- If your server IP is black listed
- If you are sending files of huge size or of certain types
- If your mail content contains certain words
- if user has a spam filter setup for certain domains
Read this page http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/html/ for more information.
Also try to use sendgrid http://sendgrid.com/transactional-email/pricing for testing your code just to make sure IP of your server is not black listed. Sendgrid has a free plan for beginners.