Failure to send secure message from openEMR to patient portal (and see warning in php log)

openEMR: 7.0.3 (4)

Getting this error trying to send a message to a patient from openEMR to portal. The message shows in openEMR’s list of sent emails, but not in the portal for the recipient. I can send emails from portal to openEMR without issue

Undefined array key “portal_username” in openemr\portal\lib\portal_mail.inc.php on line 53

The error is coming from this line:

$user = $_SESSION[‘portal_username’] ? $_SESSION[‘portal_username’] : $_SESSION[‘authUser’];

I added an isset() to $_SESSION[‘portal_username’] and that made the error go away, but I am still not seeing a message in the patient’s portal when I send from openEMR. The message shows in openEMR’s sent list. The Inbox for the patient is empty

Help?

Thanks

I see the problem (response updated. i had used less-than/greater-than delimiters in my original response, which got swallowed by the browser)

Looking in onsite_mail, for messages sent from portal to openEMR, the userid mentioned in owner, userid and recipient_id columns is [firstname][lastname][pid]

For messages sent from openEMR to portal, the userid is [firstname][pid]

If I change the owner and recipient_id for a message sent from openEMR to portal to [firstname][lastname][pid], the message then shows in the portal

It looks like portal account names have changed to now be first name + last name + ID
Previously, they were first name + ID
The logic for sending mail from openEMR to portal users is still using the old logic for the portal user name, and it not matching the currently configured portal user names.
I have a portal user I created a year ago in a prior version of openEMR (not sure which), and I can sent email to her in the current version of openEMR.
But for a user I just granted portal access to (and as such caused their portal user name to be first name + last name + ID), the email sending logic is not specifying their proper portal user name when populating records in the onsite_mail table

This was fixed just don’t recall if released and may be in next release.

Good. I’m using 7.0.3(4) which is the latest patch, and that version has the issue. Is the there a patch on github I could apply that fixes this?

I don’t have time to dig this out but look here PR #8675 if not check my other PR’s

Found your fix and applied it. Confirming that it fixed the issue. Thanks!
The first time I tried it, I sent an email from openEMR without logging out (just modified the messages.php file). Got the same issue. But after logging out and back into openEMR and trying again, this time I did see the desired email addresses in onsite_mail table.