Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #95 Sending Fails Silently #124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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