• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Forwarded to devs mail() not working, if called php script on command-line

Azurel

Silver Pleskian
Username:

TITLE

mail() not working, if called php script on command-line

PRODUCT, VERSION, OPERATING SYSTEM, ARCHITECTURE

AlmaLinux 8.6 (Sky Tiger)
Plesk Obsidian Version 18.0.44 Update #1,

PROBLEM DESCRIPTION

Since it used to work and now it doesn't, I have to assume here is a new bug or it is a new feature? ;)

STEPS TO REPRODUCE

In the past I called in cronjob like this

# /opt/plesk/php/8.1/bin/php /var/www/vhosts/example.com/httpdocs/testmail.php

PHP:
<?php

$return = mail('[email protected]', 'TESTMAIL', 'TEXT');
var_dump($return);

?>

And receive an email.

Since version 18.0.43 and possibly the ones before, I don't receive mails called from the command-line with mail() anymore. I can call the same script from the browser and it works there.

var/log/maillog

Execute in command-line (not working)
Jun 3 10:55:31 web1 plesk-sendmail[3526675]: S3526675: from=<[email protected]> to=<[email protected]>
Jun 3 10:55:31 web1 plesk-sendmail[3526676]: S3526675: add-from: stderr: PASS
Jun 3 10:55:31 web1 plesk-sendmail[3526676]: S3526675: check-quota: stderr: SKIP
Jun 3 10:55:31 web1 postfix/pickup[3508214]: 5B5D825A0D7F: uid=0 from=<root>
Jun 3 10:55:31 web1 postfix/cleanup[3526662]: 5B5D825A0D7F: message-id=<[email protected]>
Jun 3 10:55:31 web1 postfix/qmgr[3508215]: 5B5D825A0D7F: from=<[email protected]>, size=297, nrcpt=1 (queue active)
Jun 3 10:55:31 web1 postfix-local[3526683]: 5B5D825A0D7F: from=<[email protected]>, to=<[email protected]>, dirname=/var/qmail/mailnames
Jun 3 10:55:31 web1 dk_check[3526684]: 5B5D825A0D7F: DKIM Feed: No signature
Jun 3 10:55:31 web1 postfix-local[3526683]: 5B5D825A0D7F: dk_check: stderr: PASS
Jun 3 10:55:31 web1 dmarc[3526685]: 5B5D825A0D7F: SPF record was not found in Authentication-Results
Jun 3 10:55:31 web1 dmarc[3526685]: 5B5D825A0D7F: DMARC: smtpdomain=mail.PLESKDOMAIN maildomain=web1.PLESKDOMAIN mailfrom=[email protected] stamp=1654246531 ip=unknown adkim=relaxed aspf=relaxed p=REJECT sp=UNSPECIFIED pct=100 align_dkim=fail align_spf=fail spfres=unknown dkimres=unknown dmarccheck=DMARC_POLICY_REJECT dmarcstatus=STOP
Jun 3 10:55:31 web1 postfix-local[3526683]: 5B5D825A0D7F: dmarc: stderr: STOP
Jun 3 10:55:31 web1 postfix-local[3526683]: message discarded by a mail handler

Jun 3 10:55:31 web1 postfix/pipe[3526664]: 5B5D825A0D7F: to=<[email protected]>, relay=plesk_virtual, delay=0.03, delays=0/0/0/0.03, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Jun 3 10:55:31 web1 postfix/qmgr[3508215]: 5B5D825A0D7F: removed

Execute from browser (working)
Jun 3 11:01:04 web1 plesk-sendmail[3527524]: S3527524: from=<[email protected]> to=<[email protected]>
Jun 3 11:01:04 web1 plesk-sendmail[3527525]: S3527524: add-from: stderr: PASS
Jun 3 11:01:04 web1 plesk-sendmail[3527525]: S3527524: check-quota: stderr: SKIP
Jun 3 11:01:04 web1 plesk-sendmail[3527528]: S3527524: dk_sign: stderr: PASS
Jun 3 11:01:04 web1 postfix/pickup[3508214]: 92B4425A0C6F: uid=10007 from=<[email protected]>
Jun 3 11:01:04 web1 postfix/cleanup[3526662]: 92B4425A0C6F: message-id=<[email protected]>
Jun 3 11:01:04 web1 postfix/qmgr[3508215]: 92B4425A0C6F: from=<[email protected]>, size=658, nrcpt=1 (queue active)
Jun 3 11:01:04 web1 postfix-local[3527533]: 92B4425A0C6F: from=<[email protected]>, to=<[email protected]>, dirname=/var/qmail/mailnames
Jun 3 11:01:04 web1 postfix-local[3527533]: 92B4425A0C6F: dk_check: stderr: PASS
Jun 3 11:01:04 web1 dmarc[3527535]: 92B4425A0C6F: SPF record was not found in Authentication-Results
Jun 3 11:01:04 web1 postfix-local[3527533]: 92B4425A0C6F: dmarc: stderr: PASS
Jun 3 11:01:04 web1 dovecot[3527537]: service=lda, user=[email protected], ip=[]. msgid=<[email protected]>: saved mail to INBOX
Jun 3 11:01:04 web1 postfix/pipe[3527327]: 92B4425A0C6F: to=<[email protected]>, relay=plesk_virtual, delay=0.08, delays=0/0/0/0.08, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Jun 3 11:01:04 web1 postfix/qmgr[3508215]: 92B4425A0C6F: removed

ACTUAL RESULT

mail transfer failed

EXPECTED RESULT

Send mail successfully

ANY ADDITIONAL INFORMATION

I have activated mail service on web1.PLESKDOMAIN and mail.PLESKDOMAIN both with "Use DKIM spam protection system to sign outgoing email messages"

"PLESKDOMAIN" means first registered domain (hostname) in Plesk.

YOUR EXPECTATIONS FROM PLESK SERVICE TEAM

Confirm bug
 
The results of developer's investigation are here:

The test script was created:
Code:
[root@thurman-fihmbi ~]# cat /var/www/vhosts/testmail.com/httpdocs/testmail.php
<?php
// Send email
mail('[email protected]','hello','test mail function');
?>
Executed the script:
Code:
[root@thurman-fihmbi ~]# /opt/plesk/php/7.4/bin/php /var/www/vhosts/testmail.com/httpdocs/testmail.php
[root@thurman-fihmbi ~]#
The mail message was sent:
Code:
[root@thurman-fihmbi ~]# tail -fn0 /var/log/maillog
Jun 14 11:59:42 thurman-fihmbi plesk-sendmail[109121]: S109121: from=<[email protected]> to=<[email protected]>
Jun 14 11:59:42 thurman-fihmbi plesk-sendmail[109122]: S109121: add-from: stderr: PASS
Jun 14 11:59:42 thurman-fihmbi plesk-sendmail[109122]: S109121: py-limit-out: stderr: INFO:__main__:Setting 'X-PPP-Vhost' header to 'thurman-fihmbi.srv.dev.solus.io'
Jun 14 11:59:42 thurman-fihmbi plesk-sendmail[109122]: S109121: py-limit-out: stderr: PASS
Jun 14 11:59:42 thurman-fihmbi plesk-sendmail[109122]: S109121: check-quota: stderr: SKIP
Jun 14 11:59:42 thurman-fihmbi postfix/pickup[60763]: B2BD64605C76: uid=0 from=<root>
Jun 14 11:59:42 thurman-fihmbi postfix/cleanup[109132]: B2BD64605C76: message-id=<[email protected]>
Jun 14 11:59:42 thurman-fihmbi postfix/qmgr[60762]: B2BD64605C76: from=<[email protected]>, size=498, nrcpt=1 (queue active)
Jun 14 11:59:43 thurman-fihmbi postfix/smtp[109135]: B2BD64605C76: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[173.194.76.26]:25, delay=1.1, delays=0.03/0.01/0.68/0.36, dsn=2.0.0, status=sent (250 2.0.0 OK  1655207983 o19-20020a05600c4fd300b0039c552c48e7si12971858wmq.97 - gsmtp)
Jun 14 11:59:43 thurman-fihmbi postfix/qmgr[60762]: B2BD64605C76: removed
Mail is received. The mail functionality via the command line is working as expected.

As I can see from log, the issue is related to DMARC:
Code:
Jun 3 10:55:31 web1 dmarc[3526685]: 5B5D825A0D7F: DMARC: smtpdomain=mail.PLESKDOMAIN maildomain=web1.PLESKDOMAIN [email protected] stamp=1654246531 ip=unknown adkim=relaxed aspf=relaxed p=REJECT sp=UNSPECIFIED pct=100 align_dkim=fail align_spf=fail spfres=unknown dkimres=unknown dmarccheck=DMARC_POLICY_REJECT dmarcstatus=STOP
Jun 3 10:55:31 web1 postfix-local[3526683]: 5B5D825A0D7F: dmarc: stderr: STOP
Jun 3 10:55:31 web1 postfix-local[3526683]: message discarded by a mail handler
It is possibly affected by the known bug PPPM-7190:
https://support.plesk.com/hc/en-us/...message-or-DMARC-message-moved-to-QUARANTINE-

Workaround: Modify the DMARC record of the recipient domain: Change "p=quarantine" or "p=reject" to "p=none" at Domains > example.com > DNS Settings.
If the suggested workaround does not help. I would recommend creating a request to Plesk support to investigate such behaviour further.
 
Code:
$return = mail('[email protected]', 'TESTMAIL', 'TEXT');
One potential fix could be to add the "fifth parameter" to the PHP mail command, because transport might be denied if the sender's address is not an address that the mail server is aware of. You might need something like "-f [email protected]" as the fifth mail() parameter to get it to work.
 
Yes, my DMARC record is p=reject. Set to "none" make no sense, in that case DMARC has no use at all. ;)

Your hint with -f is working. Thank you very much. :)
Maybe this should be "Workaround 3" in your linked support ticket.
 
Back
Top