I'm trying to
develop an invitation system for my website which runs on CakePHP 1.3.4.
I am trying to use the built in EmailComponent to send an email. I'm getting this error (expanded):
Notice (8): Undefined property: EmailComponent::$Controller [CORE/cake/libs/controller/components/email.php, line 428]
Code | Context
*/
function _render($content) {
$viewClass = $this-Controller-view;
$content = array(
"",
""
)
EmailComponent::_render() - CORE/cake/libs/controller/components/email.php, line 428
EmailComponent::send() - CORE/cake/libs/controller/components/email.php, line 368
UsersController::send_quick_add_email() - APP/controllers/users_controller.php, line 77
UsersController::quick_add() - APP/controllers/users_controller.php, line 104
SinglesResultsController::quick_add() - APP/controllers/singles_results_controller.php, line 63
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
I also get the following, which I can expand if necessary:
Notice (8): Trying to get property of non-object [CORE/cake/libs/controller/components/email.php, line 428]
Notice (8): Undefined property: EmailComponent::$Controller [CORE/cake/libs/controller/components/email.php, line 433]
Notice (8): Trying to get property of non-object [CORE/cake/libs/controller/components/email.php, line 433]
Notice (8): Undefined property: View::$webroot [CORE/cake/libs/view/view.php, line 805]
Warning (2): Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/cake/cake/libs/debugger.php:673) [CORE/cake/libs/controller/controller.php, line 746]
I think that the EmailComponent object holds a reference to the controller it's being called from. I don't know why it's undefined in this case. Here is the code that fails (specifically, it errors on the call to $this-Email-send()):
function send_quick_add_email($email)
{
if($email)
{
$this->Email->reset();
$this->Email->to = $email;
$this->Email->subject = 'Some subject text';
$this->Email->from = '
[email protected]';
$this->Email->template = 'email_template';
$this->set('user', $user);
$this->set('token', $token);
$this->Email->delivery = 'debug';
$this->Email->send();
}
}
Ok, for more clarification:
The main data I am collecting on the site is results of a game played in meatspace. SinglesResultsController has an action, quick_add, which expects email addresses of people not already registered on the site. If the email addresses aren't associated with Users, UsersController::quick_add is called, which creates an inactive user, and sends an invitation email in UsersController::send_quick_add_email()
I think the problem is related to the fact that the email isn't being sent in the first controller initialized (SinglesResultsController).
Any thoughts on how to make it work? The Email component is declared at the top of both Controllers.