Note to self: All that lines are not necessary. What works is:
<?php
class ErinnerungShell extends Shell {
/**
* List of tasks for this shell
*
* @var array
*/
var $tasks = array('Email');
var $uses = array('Vertrag');
var $Email;
function main()
{
....some code...
$this->emailversenden($vertrag);
}
function emailversenden($vertrag)
{
$user = ....;
$responsibleperson = ....;
$responsiblepersonname = ....;
$responsiblepersonemail = ....;
$username= ....;
$useremail= ....;
//it looks like somehow set with compact doesn't really work
here
$this->Email->set('user',$user);
$this->Email->set('vertrag',$vertrag);
$this->Email->set('responsibleperson',$responsibleperson);
$this->Email->set('somemoretext',$somemoretext);
$this->Email->settings(array(
'from' => '[email protected]',
'template' => 'simple_message2', //this is my email layout under
elements
'to' => $responsiblepersonname.' <'.$responsiblepersonemail.'>',
'cc' => $username.' <'.$useremail.'>',
'subject' => 'Erinnerung: Vertrag kündigen
'.$vertrag['Lieferant']['name'],
'sendAs' => 'html'
));
$this->Email->send();
}
}
?>
This sends me nicely formatted emails from console, although I get an annoying
warning :
PHP Warning: Invalid argument supplied for foreach() in
/usr/share/cake/libs/controller/components/email.php on line 457
Line 457 is:
if (!empty($this->bcc) && $this->delivery != 'smtp') {
$this->__header[] = 'Bcc: ' .implode(', ',
array_map(array($this, '__formatAddress'), $this->bcc));
}
Well... Bcc is clearly empty in my setup so im am wondering where this error
comes from.
Any hints are appreciated
Anja
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag
von Liebermann, Anja Carolin
Gesendet: Freitag, 3. April 2009 12:16
An: [email protected]
Betreff: AW: Sending emails in console scripts
Hi,
I am just running into the same problem. Have you found a solution yet?
I want to send an email via a shell script and have trouble passing teh body to
the Email component when using the mail functions from the example shell script
"my". I will now try your solution.
Anja
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag
von [email protected]
Gesendet: Mittwoch, 21. Januar 2009 13:20
An: CakePHP
Betreff: Sending emails in console scripts
Hi.
I'm writing a console shell that needs to send emails. I want to use the
EmailComponent but the only way i've managed to get it to work is to manually
create an instance of AppController an pass it to a manually created instance
of EmailComponent.
My code:
App::import('Core', 'Controller');
App::import('Controller', 'AppController'); $AppController = new
AppController(); $AppController->constructClasses();
App::import('Component', 'Email');
$Email = new EmailComponent();
$Email->initialize($AppController);
$Email->startup($AppController);
Is there a simpler/more elegant way of achieving this? Shouldn't Shell have a
$components variable the same way it has a $uses variable?
Thanks in advance.
Gonçalo Marrafa
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---