Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions administrator/components/com_messages/Model/MessageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,40 +360,62 @@ public function save($data)
// Send the email
$mailer = Factory::getMailer();

if (!$mailer->addReplyTo($fromUser->email, $fromUser->name))
try
{
try
if (!$mailer->addReplyTo($fromUser->email, $fromUser->name))
{
Log::add(Text::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO'), Log::WARNING, 'jerror');
try
{
Log::add(Text::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO'), Log::WARNING, 'jerror');
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_('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;
}
catch (\RuntimeException $exception)

if (!$mailer->addRecipient($toUser->email, $toUser->name))
{
Factory::getApplication()->enqueueMessage(Text::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_REPLYTO'), 'warning');
try
{
Log::add(Text::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_RECIPIENT'), Log::WARNING, 'jerror');
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_('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;
}

// 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);

if (!$mailer->addRecipient($toUser->email, $toUser->name))
$mailer->Send();
}
catch (\Exception $exception)
{
try
{
Log::add(Text::_('COM_MESSAGES_ERROR_COULD_NOT_SEND_INVALID_RECIPIENT'), Log::WARNING, 'jerror');
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');

$this->setError(Text::_('COM_MESSAGES_ERROR_MAIL_FAILED'), 500);

return false;
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_('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;
}
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');

$mailer->setSubject($subject);
$mailer->setBody($msg);
$this->setError(Text::_('COM_MESSAGES_ERROR_MAIL_FAILED'), 500);

$mailer->Send();
return false;
}
}
}

return true;
Expand Down
50 changes: 35 additions & 15 deletions administrator/components/com_users/Model/MailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;

/**
* Users mail model.
Expand Down Expand Up @@ -170,28 +171,47 @@ public function send()
$mailer = Factory::getMailer();
$params = ComponentHelper::getParams('com_users');

// Build email message format.
$mailer->setSender(array($app->get('mailfrom'), $app->get('fromname')));
$mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject));
$mailer->setBody($message_body . $params->get('mailBodySuffix'));
$mailer->IsHtml($mode);

// Add recipients
if ($bcc)
try
{
$mailer->addBcc($rows);
$mailer->addRecipient($app->get('mailfrom'));
// Build email message format.
$mailer->setSender(array($app->get('mailfrom'), $app->get('fromname')));
$mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject));
$mailer->setBody($message_body . $params->get('mailBodySuffix'));
$mailer->IsHtml($mode);

// Add recipients
if ($bcc)
{
$mailer->addBcc($rows);
$mailer->addRecipient($app->get('mailfrom'));
}
else
{
$mailer->addRecipient($rows);
}

// Send the Mail
$rs = $mailer->Send();
}
else
catch (\Exception $exception)
{
$mailer->addRecipient($rows);
try
{
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');

$rs = false;
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');

$rs = false;
}
}

// Send the Mail
$rs = $mailer->Send();

// Check for an error
if ($rs instanceof \Exception)
if ($rs !== true)
{
$app->setUserState('com_users.display.mail.data', $data);
$this->setError($rs->getError());
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.com_messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COM_MESSAGES_ERROR_INVALID_FROM_USER="Invalid sender"
COM_MESSAGES_ERROR_INVALID_MESSAGE="Invalid message content"
COM_MESSAGES_ERROR_INVALID_SUBJECT="Invalid subject"
COM_MESSAGES_ERROR_INVALID_TO_USER="Invalid recipient"
COM_MESSAGES_ERROR_MAIL_FAILED="The email could not be sent."
COM_MESSAGES_FIELD_AUTO_PURGE_LABEL="Auto-delete Messages (days)"
COM_MESSAGES_FIELD_DATE_TIME_LABEL="Posted"
COM_MESSAGES_FIELD_LOCK_LABEL="Lock Inbox"
Expand Down
57 changes: 38 additions & 19 deletions components/com_contact/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;

/**
* Controller for single contact view
Expand Down Expand Up @@ -221,30 +222,48 @@ private function _sendEmail($data, $contact, $copy_email_activated)
}
}

$mail = Factory::getMailer();
$mail->addRecipient($contact->email_to);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($sitename . ': ' . $subject);
$mail->setBody($body);
$sent = $mail->Send();

// If we are supposed to copy the sender, do so.

// Check whether email copy function activated
if ($copy_email_activated == true && !empty($data['contact_email_copy']))
try
{
$copytext = Text::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
$copytext .= "\r\n\r\n" . $body;
$copysubject = Text::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);

$mail = Factory::getMailer();
$mail->addRecipient($email);
$mail->addRecipient($contact->email_to);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($copysubject);
$mail->setBody($copytext);
$mail->setSubject($sitename . ': ' . $subject);
$mail->setBody($body);
$sent = $mail->Send();

// If we are supposed to copy the sender, do so.

// Check whether email copy function activated
if ($copy_email_activated == true && !empty($data['contact_email_copy']))
{
$copytext = Text::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
$copytext .= "\r\n\r\n" . $body;
$copysubject = Text::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);

$mail = Factory::getMailer();
$mail->addRecipient($email);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($copysubject);
$mail->setBody($copytext);
$sent = $mail->Send();
}
}
catch (\Exception $exception)
{
try
{
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');

$sent = false;
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');

$sent = false;
}
}

return $sent;
Expand Down
27 changes: 25 additions & 2 deletions components/com_mailto/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;

/**
* Mailer Component Controller.
Expand Down Expand Up @@ -153,11 +154,33 @@ public function send()
$from = MailHelper::cleanAddress($from);
$email = PunycodeHelper::emailToPunycode($email);

// Send the email
if (Factory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
// Try to send the email
try
{
$return = Factory::getMailer()->sendMail($from, $sender, $email, $subject, $body);
}
catch (\Exception $exception)
{
try
{
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');

$return = false;
}
catch (\RuntimeException $exception)
{
Factory::getApplication()->enqueueMessage(Text::_($exception->errorMessage()), 'warning');

$return = false;
}
}

if ($return !== true)
{
$this->setMessage(Text::_('COM_MAILTO_EMAIL_NOT_SENT'), 'notice');

$this->setRedirect('index.php', 'COM_MAILTO_EMAIL_NOT_SENT');

return $this->mailto();
}

Expand Down
Loading