Skip to content

Commit

Permalink
Change email notification to use site from address (Fix #9261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Jan 8, 2017
1 parent 5d08c45 commit db2e207
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 37 additions & 1 deletion administrator/components/com_messages/models/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,43 @@ public function save($data)
$msg = sprintf($lang->_('COM_MESSAGES_PLEASE_LOGIN'), $siteURL);

// Send the email
JFactory::getMailer()->sendMail($fromUser->email, $fromUser->name, $toUser->email, $subject, $msg);
$mailer = JFactory::getMailer();

if (!$mailer->addReplyTo($fromUser->email, $fromUser->name))
{
try
{
JLog::add(JText::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO'), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO'), 'warning');
}

// The message is still saved in the database, we do not allow this failure to cause the entire save routine to fail
return true;
}

if (!$mailer->addRecipient($toUser->email, $toUser->name))
{
try
{
JLog::add(JText::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_RECIPIENT'), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_RECIPIENT'), 'warning');
}

// The message is still saved in the database, we do not allow this failure to cause the entire save routine to fail
return true;
}

$mailer->setSubject($subject);
$mailer->setBody($msg);

// The Send method will raise an error via JError on a failure, we do not need to check it ourselves here
$mailer->Send();
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COM_MESSAGES_CONFIG_SAVED="Configuration successfully saved."
COM_MESSAGES_CONFIGURATION="Messages: Options"
COM_MESSAGES_ERR_INVALID_USER="Invalid user"
COM_MESSAGES_ERR_SEND_FAILED="The user has locked their mailbox. Message failed."
COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_RECIPIENT="The email message cannot be sent due to an invalid recipient address."
COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO="The email message cannot be sent due to an invalid reply-to address."
COM_MESSAGES_ERROR_INVALID_FROM_USER="Invalid sender"
COM_MESSAGES_ERROR_INVALID_MESSAGE="Invalid message content"
COM_MESSAGES_ERROR_INVALID_SUBJECT="Invalid subject"
Expand Down

0 comments on commit db2e207

Please sign in to comment.