Skip to content

Commit

Permalink
Fixes #95
Browse files Browse the repository at this point in the history
Added try catch to $mailer->send() to catch any mailer specifc errors.
  • Loading branch information
Tyler committed Apr 12, 2018
1 parent 3603128 commit 0ef88f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
- Fixed a bug where single carriage returns in a `<textarea>` would be lost in the email. ([#118](https://github.com/craftcms/contact-form/issues/118))
- Fixed a bug where HTML was not being properly escaped in an email body. ([#104](https://github.com/craftcms/contact-form/issues/104))
- Fixed a bug where an empty file attachment field caused an error instead of sending an email without attachments. ([#116](https://github.com/craftcms/contact-form/pull/116))
- Fixed a bug where sending fails silently. ([#95](https://github.com/craftcms/contact-form/issues/95))

## 2.1.1 - 2017-12-04

Expand Down
9 changes: 8 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use craft\helpers\FileHelper;
use craft\helpers\StringHelper;
use craft\mail\Message;
use Swift_TransportException;
use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
Expand Down Expand Up @@ -99,7 +100,13 @@ public function send(Submission $submission, bool $runValidation = true): bool

foreach ($toEmails as $toEmail) {
$message->setTo($toEmail);
$mailer->send($message);
try {
return $mailer->send($message);
} catch (Swift_TransportException $e) {
Craft::error('Error sending email: '.$e->getMessage());
Craft::$app->getErrorHandler()->logException($e);
return false;
}
}

// Fire an 'afterSend' event
Expand Down

0 comments on commit 0ef88f4

Please sign in to comment.