Your component needs to get a handle on the controller. Add this:

function startup(&$controller) {
        $this->controller = $controller;
}

.. and change any $controller to $this->controller

Another couple of things worth mentioning: I'm not sure when this
change happened, but I recently ran into a problem with my own version
of the well-traveled SwiftMailer component. I'd been using the output
buffer like so:

ob_start();
$this->controller->render(null, null, $view);
$plain_msg = strip_tags(ob_get_clean());

and

ob_start();
$this->controller->render(null, $this->layout, $view);
$html_msg = ob_get_clean();

It was always failing and I tracked it down to the fact that
View::render was already buffering. So I removed that.

Then, my messages were being sent but were screwed up. At first it
appeared as if the division between the plain & html parts had been
corrupted, as the plaintext version was visible above the html. That
was a red herring though, because the plaintext was, in fact,
duplicated. It turned out that $controller->output is concatenated, so
I had to set to null between rendering the parts:

$old_layout = $this->controller->layout;
$this->controller->layout = '';
$plain_msg = $this->controller->render(null, null, $view);
$this->controller->layout = $old_layout;

/* $controller->output is concatenated, so it must be set to null
 * after each render()
 */
$this->controller->output = null;

if ($html)
{
...

I don't know if that's the correct way to deal with it but it works
for me. Just thought I'd let you know on the chance I save you some
head-scratching.


On Thu, Jan 8, 2009 at 11:00 AM, Brenda <[email protected]> wrote:
>
> I just upgraded from RC3 to 1.2 final, and I'm getting errors when
> sending email.
>
> I have my own component:
>
> class MyEmailComponent extends Object {
>
>        var $components = array ('Email');
>
>        function sendEmail($to,$subject=null) {
>                // The calling controller must first set:
>                // messageText
>                // messageHTML (if blank, messageText is used)
>                // msgTitle (optional)
>                // subtitle (optional)
>
>                if (!$subject) {
>                        $subject = 'A Message from MySite.com';
>                }
>
>                $this->Email->to = $to;
>                $this->Email->subject = $subject;
>                // $this->Email->replyTo = '[email protected]';
>                $this->Email->from = '[email protected]';
>                $this->Email->layout = 'default';
>                $this->Email->template = 'default'; // note no '.ctp'
>                // Send as 'html', 'text' or 'both' (default is 'text')
>                $this->Email->sendAs = 'both'; // because we like to send 
> pretty
> mail
>
>                // Do not pass any args to send()
>                if ($this->Email->send()) {
>                        return true;
>                } else {
>                        return false;
>                }
>
>
>        }
>
> }
>
>
>
>
> It is called from a function inside a controller:
>
>        function _notify($message_id) {
>                // Send email notification of private message
>                $to = $this->PrivateMessage->getRecipientEmail($message_id);
>                $subject = 'You have a message on the MySite.com website';
>                $this->set('title','A New Private Message is waiting for you 
> on the
> MySite.com website');
>                $this->set('messageText','A new message is waiting for you on 
> the
> MySite.com website. Log into the member area to view your messages.');
>                $this->set('messageHTML','<p>A new message is waiting for you 
> on the
> <a href="http://MySite.com/privateMessages/";>MySite.com</a>
> website.');
>
>
>                if ($this->MyEmail->sendEmail($to,$subject) ) {
>                        return true;
>                } else {
>                        return false;
>                }
>
>
>        }
>
>
>
> It generates these messages:
>
> Notice (8): Undefined property: EmailComponent::$Controller [CORE\cake
> \libs\controller\components\email.php, line 352]
>
> Notice (8): Trying to get property of non-object [CORE\cake\libs
> \controller\components\email.php, line 352]
>
> Notice (8): Undefined property: EmailComponent::$Controller [CORE\cake
> \libs\controller\components\email.php, line 359]
> Notice (8): Trying to get property of non-object [CORE\cake\libs
> \controller\components\email.php, line 359]
>
>
> Notice (8): Undefined property: View::$webroot [CORE\cake\libs\view
> \view.php, line 751]
>
> Warning (2): Cannot modify header information - headers already sent
> by (output started at D:\cakephp\cake\libs\debugger.php:521) [CORE\cake
> \libs\controller\controller.php, line 615]
>
>
> The email is sent, but it has a error message rather than the message
> text.
>
>
> Any suggestions as to where to look for what went wrong?
>
> Thank you so much for your help.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to