PR-5.2-dev Pending

User tests: Successful: 0 Unsuccessful: 0

avatar Amaan-ali03
Amaan-ali03
15 Mar 2025

Pull Request for Issue #44927

Summary of Changes

Fixed an issue where setting custom_reply = true in com_contact caused an exception.
Previously, the API incorrectly threw an exception when the message was processed by a plugin but $sent was still false.
Fix applied:
Updated $sent logic to correctly check if a plugin processed the message.
Prevented an unnecessary exception when custom_reply is enabled.

Testing Instructions

Steps to reproduce the issue
Set custom_reply parameter to true in com_contact
Try to send a message using API
Send API request:
curl -X POST "http://localhost/joomla/api/index.php/v1/contact"
-H "Content-Type: application/json"
-d '{"name": "John Doe", "email": "test@example.com", "subject": "Test", "message": "Hello!", "custom_reply": true}'
Before Fix: API throws an exception when custom_reply = true.

After Fix: API returns success:
{ "message": "Contact message processed successfully." }

Actual result BEFORE applying this Pull Request

Exception is thrown even if the plugin processes the message successfully.

Expected result AFTER applying this Pull Request

1-No exception is thrown when custom_reply = true and the message is handled by a plugin.
2-API successfully processes messages with custom replies.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar Amaan-ali03 Amaan-ali03 - open - 15 Mar 2025
avatar Amaan-ali03 Amaan-ali03 - change - 15 Mar 2025
Status New Pending
avatar Amaan-ali03 Amaan-ali03 - change - 15 Mar 2025
Labels Added: PR-5.2-dev
avatar fgsw
fgsw - comment - 16 Mar 2025

@Amaan-ali03 Please change the title to "[5.2] Prevent exception when custom_reply is enabled in com_contact API".

avatar Amaan-ali03 Amaan-ali03 - change - 16 Mar 2025
Title
Fix: Prevent exception when custom_reply is enabled in com_contact API
[5.2] Prevent exception when custom_reply is enabled in com_contact API
avatar Amaan-ali03 Amaan-ali03 - edited - 16 Mar 2025
avatar Amaan-ali03
Amaan-ali03 - comment - 16 Mar 2025

@Amaan-ali03 Please change the title to "[5.2] Prevent exception when custom_reply is enabled in com_contact API".

Changed the title ... Thank you for the feedback

avatar alikon
alikon - comment - 16 Mar 2025

with this pr
image

avatar Amaan-ali03
Amaan-ali03 - comment - 16 Mar 2025

with this pr image

@alikon Thanks for testing! I'll investigate the 500 error by checking logs and debugging _sendEmail().
I'll update the PR once I find and fix the issue.
Any suggestions on the fixing would be helpful .

avatar HermanPeeren
HermanPeeren - comment - 16 Mar 2025

You misunderstood my comment. The failure is not in _sendMail(), but in your changed code.

You took out the $sent=false;, but then checking if ($sent) should be within the if (!$params->get('custom_reply')) part. Also not good that you took out the comment // Send the email. Please check the logic of it; read the code! It would also help if you do a little test for yourself to see if it works before sending the changed code. Thank you.

This is what I had in mind (1 time exception, for it is better if you would figure it out yourself):


        // Send the email
        $params = ComponentHelper::getParams('com_contact');

        if (!$params->get('custom_reply')) {
            $sent = $this->_sendEmail($data, $contact, $params->get('show_email_copy', 0));

            if (!$sent) {
                throw new SendEmail('Error sending message');
            }
        }

You see what I mean?
Also mind the white line above it.

As an aside: coding often is a trade-off between several disadvantages. This solution is a small example of that: it slightly increases conditional complexity with the nested if, but it results in a bit less cognitive load when you read the code, because things that belong together are put together.

Add a Comment

Login with GitHub to post a comment