Solution for RFC 5321 and RFC 5322. compliance for old version of OJS and OCS

Hello all, I think this message can be of help for whoever is stuck with an old version of OJS or is still using OCS (Open Conference System) .

In latest months mailservers have further tightened their policies in observance with most recent RFCs, so mail messages built by older version of OJS and all versions of OCS are not compliant with latest version of RFC 5321 and RFC 5322.

In our case, for example we had to face the problem of messages sent by OJS and OCS with sender addresses not belonging to same domain of the mailserver used to send the message.

For this reason we backported the code implemented since OJS 3.1.2

We luckily discovered that required modifications are not dependant on PHP version or PHPMailer version (in a vintage OCS version PHPMailer is not even used).

The code to be modified is located in (the path to the file depends on whether you are using either OJS or OCS and which version of it)

The code modifications change the way the FROM field and REPLY-TO field of mail messages are filled in with respect with original code.

The use of the new feature is configure by a few additional parameters you have to put in


default_envelope_sender =

; Force the default envelope sender (if present)
; This is useful if setting up a site-wide no-reply address
; The reply-to field will be set with the reply-to or from address.
; force_default_envelope_sender = Off - RINO
force_default_envelope_sender = On

; Force a DMARC compliant from header (RFC5322.From)
; If any of your users have email addresses in domains not under your control
; you may need to set this to be compliant with DMARC policies published by
; those 3rd party domains.
; Setting this will move the users address into the reply-to field and the
; from field wil be rewritten with the default_envelope_sender.
; To use this you must set force_default_enveloper_sender = On and
; default_envelope_sender must be set to a valid address in a domain you own.
; force_dmarc_compliant_from = Off - RINO
force_dmarc_compliant_from = On

; The display name to use with a DMARC compliant from header
; By default the DMARC compliant from will have an empty name but this can
; be changed by adding a text here.
; You can use ‘%n’ to insert the users name from the original from header
; and ‘%s’ to insert the localized sitename.
; dmarc_compliant_from_displayname = ‘%n via %s’ - RINO
dmarc_compliant_from_displayname = ‘%n via %s’

In you have to modify a little portion of the send method where From and Reply-To fields are filled:

if ($this->getFrom() != null) {
if (Config::getVar(‘dmarc’, ‘force_default_envelope_sender’) && Config::getVar(‘dmarc’, ‘default_envelope_sender’)
&& Config::getVar(‘dmarc’, ‘force_dmarc_compliant_from’)) {
/* If a DMARC compliant RFC5322.From was requested we need to promote the original RFC5322.From into a Reply-to header
* and then munge the RFC5322.From */
$alreadyExists = false;
//foreach ((array) $this->getReplyTo() as $r) {
// if ($r[‘email’] === $from) {
// $alreadyExists = true;
// }
if (!$alreadyExists) {
$this->addHeader(‘Reply-To’, $f[‘email’]);

  // Munge the RFC5322.From
  if (Config::getVar('dmarc', 'dmarc_compliant_from_displayname')) {
     $patterns = array('#%n#', '#%s#');
     $replacements = array($f['name'], 'ANIDIS XIX & ASSISi XVII - 2022');
     $f['name'] = preg_replace($patterns, $replacements, Config::getVar('dmarc', 'dmarc_compliant_from_displayname'));
  } else {
     $f['name'] = '';
  $f['email'] = Config::getVar('dmarc', 'default_envelope_sender');

// this sets both the envelope sender (RFC5321.MailFrom) and the From: header (RFC5322.From)

$this->addHeader(‘From’, $f[‘name’].’ <’.$f[‘email’].’>’);