Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Contact form is sending to gmail spam folder

I have recently created a contact form in PHP and it sends the message fine, but it is sending it to my spam folder in my gmail. I am using php mailer.

Does anyone know why it's doing this?

3 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Stephanie,

If you're using a shared host to host your website, this could be the reason, as the server you're on may have some spammy sites on it. You have a couple of options.

  1. Since you're only using your contact form to send emails to yourself, you can simply mark those emails as not spam, and even set up a rule in Gmail to ensure you get those messages in your inbox, perhaps with a label as well.
  2. Use a 3rd party mail service like mailgun. They have a nice API and it wouldn't be too hard to use it on your site using PHP. Their documentation is good.

Good luck!

-Greg

Emmanuel Plouvier
Emmanuel Plouvier
11,919 Points

Hi,

This is often of mail heading problem or with the "reputation" of your server.

To know more, you can read :

Devron Baldwin
Devron Baldwin
3,508 Points

In my experience it's generally the SPF record being set up incorrectly.

Thanks for your help Greg, I will take your advice on board and look into this,