Why my email sent using another domain goes to spam?

I just installed my mail server by following tutorials below:

How to Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 16.04 How To use an SPF Record to Prevent Spoofing & Improve E-mail Reliability How To Install and Configure DKIM with Postfix on Debian Wheezy

On the server that i installed mail server, i using 2 domains (domain1 and domain2) with different record for each domain (TXT, MX, NS, A)

I test sent my email using standard PHP mail function using domain1 and that’s successfully not goes to spam to Gmail.

But, when i test sent email from domain2, the email goes to spam on Gmail, where ‘mailed-by’ on email detail is using domain1.

So, how i solve this? Thanks before …


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

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.

How did you make that your sent e-mails didn’t go to spam? I have a domain and mail server (iredmail) and all of my sent mails go to spam (gmail). Can you help me?

Does your SPF record for both domains allow the server to send mail on its behalf?