email goes to spam (gmail), PHP

i managed to make sendmail work and i can send email out with mail() in PHP. however that email always goes to spam. my domain is new, has never been used before. i read that i have to create reverse DNS (i really have no idea how to do it) to avoid emails to be delivered to spam folder. does anyone know what exactly do i have to do to see email sent from my php script to appear in INBOX (gmail)?

thank you!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


you are right, you need a reverse DNS record. DigitalOcean sets this record based on the hostname of your droplet automatically. You can check your settings with the command:

jkostolansky@server:~$ hostname

If you wish to update your rDNS record, you can rename your droplet in the control panel:

  1. navigate to the droplet listing
  2. select the droplet to rename
  3. choose the “Settings” tab and the “Rename” option
  4. fill in the “New Hostname” field and click the “Rename” button

And I recommend you to create SPF and DKIM records, too.

You’re PTR should coincide with your hostname, just ask DO to update your PTR.