SPF + DKIM pass, but still going to spam when sending via PHP (virtualmin server)

Hey all,

Running mail through a Webmin/Virtualmin setup.

SPF, DKIM, and reverse DNS all check out fine — I even tested here:

When I send using authenticated SMTP (Roundcube), delivery is fine.

But when a PHP script sends mail (e.g., contact form), Outlook and sometimes Gmail mark it as spam.

Same domain, same IP — only difference is how it’s sent.

Could this be due to headers missing in PHP mail() or something with the Return-Path?

Appreciate any pointers from folks running similar setups.

according to that link DKIM is invalid.

maybe try setting it to relaxed rather than simple if it is valid over SMTP for some reason.

Mxtool reporting the DKIM incorrect as well

Does the script send through a Postfix user or use PHP as the mailer? If it sends it out directly then nothing you set up in Postfix is used. With some forms they used to give an option to send authenticated email through a user account. I think that’s what you want?

emails that are sent with a PHP script eg mail() get an immediate spam point score of 5.

I cannnot remember the exact rule, but is it part of an additional test set that not every spamassassain has, but they might now.

Strange thing is when i test using smtp i get 10/10 score and the issue is happening only when i use php mail function. I am using smtp to send via php mail function.

SMTP does not get the extra points. Php script sending mail = bad

1 Like

No. This is not strange. As I said above, your PHP mail function doesn’t have SPF or DKIM. It only gets these when set up like in Postfix. Look for a script that doesn’t use the PHP mail function but sends through a user account set up in Postfix. PHP doesn’t magically get the settings from Postfix. They are two independent things.

1 Like

use an SMTP plugin -if available- for website, or use smtp settings with authentication in php.
without smtp settings, php sends unauthenticated (=spam)

2 Likes