diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 5e2bb9d03ae..30b1d7f6cd6 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -269,6 +269,24 @@ class EmailComponent extends Component { */ public $messageId = true; +/** + * Controller reference + * + * @var object Controller + */ + protected $_controller = null; + +/** + * Constructor + * + * @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components + * @param array $settings Array of configuration settings. + */ + public function __construct(ComponentCollection $collection, $settings = array()) { + $this->_controller = $collection->getController(); + parent::__construct($collection, $settings); + } + /** * Initialize component * @@ -330,7 +348,7 @@ public function send($content = null, $template = null, $layout = null) { if ($layout) { $this->layout = $layout; } - $lib->layout($this->layout, $this->template)->emailFormat($this->sendAs); + $lib->layout($this->layout, $this->template)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs); if (!empty($this->attachments)) { $lib->attachments($this->_formatAttachFiles()); diff --git a/lib/Cake/tests/Case/Controller/Component/EmailComponentTest.php b/lib/Cake/tests/Case/Controller/Component/EmailComponentTest.php index 59f9dd5d65c..fb0b8cb3e9d 100644 --- a/lib/Cake/tests/Case/Controller/Component/EmailComponentTest.php +++ b/lib/Cake/tests/Case/Controller/Component/EmailComponentTest.php @@ -272,6 +272,7 @@ function testTemplates() { $this->Controller->EmailTest->layout = 'default'; $this->Controller->EmailTest->template = 'default'; + $this->Controller->set('title_for_layout', 'Email Test'); $text = <<