Skip to content

Commit

Permalink
Logger: added fromEmail option to set From header [Closes #109]
Browse files Browse the repository at this point in the history
Useful for hostings where From email headers in php mail() are
restricted to concrete ones.
  • Loading branch information
Filip Čonka authored and dg committed May 3, 2015
1 parent 8267fda commit 37206e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Bridges/Nette/TracyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class TracyExtension extends Nette\DI\CompilerExtension
{
public $defaults = array(
'email' => NULL,
'fromEmail' => NULL,
'logSeverity' => NULL,
'editor' => NULL,
'browser' => NULL,
Expand Down Expand Up @@ -68,9 +69,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
unset($options['bar'], $options['blueScreen']);
foreach ($options as $key => $value) {
if ($value !== NULL) {
$key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
$initialize->addBody($container->formatPhp(
'Tracy\Debugger::$? = ?;',
Nette\DI\Compiler::filterArguments(array($key, $value))
'Tracy\Debugger::' . $key . ' = ?;',
Nette\DI\Compiler::filterArguments(array($value))
));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Tracy/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Logger implements ILogger
/** @var string|array email or emails to which send error notifications */
public $email;

/** @var string sender of email notifications */
public $fromEmail;

/** @var mixed interval for sending email is 2 days */
public $emailSnooze = '2 days';

Expand Down Expand Up @@ -183,7 +186,7 @@ public function defaultMailer($message, $email)
array("\n", PHP_EOL),
array(
'headers' => implode("\n", array(
"From: noreply@$host",
"From: " . ($this->fromEmail ?: "noreply@$host"),
'X-Mailer: Tracy',
'Content-Type: text/plain; charset=UTF-8',
'Content-Transfer-Encoding: 8bit',
Expand Down

0 comments on commit 37206e0

Please sign in to comment.