User tests: Successful: 0 Unsuccessful: 0
Pull Request for Issue #44927
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.
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." }
Exception is thrown even if the plugin processes the message successfully.
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.
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
Status | New | ⇒ | Pending |
Labels |
Added:
PR-5.2-dev
|
Title |
|
@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
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.
@Amaan-ali03 Please change the title to "[5.2] Prevent exception when custom_reply is enabled in com_contact API".