i wish to send mass email using cakephp shell cron job. I started with sending mail to a single person. It isn't working. Below is my code:
<?php
error_reporting(0);
class MyShell extends Shell {
/**
* List of tasks for this shell
*
* @var array
*/
var $tasks = array('Email');
/**
* Email task
*
* @var EmailTask
*/
var $Email;
/**
* Startup method for the shell
*
* Lets set some default params for the EmailTask
*
*/
function startup() {
$this->Email->settings(array(
'from' => 'tempEmail@gmail.com',
'template' => 'test'
));
}
/**
* Send just one email
* i call this function in shell
*/
function sendMeAnEmail() {
//~ $this->out('Hello world.');
return $this->Email->send(array(
'to' => 'tempEmail1@yahoo.in',
'subject' => 'Talking to myself'
));
}
/**
* Send multiple emails, change a few variables on the fly
* and test that we can 'set' variables to the view
*
//~ */
function sendMyFriendsAnEmail() {
$myFriends = array('abc@yahoo.in', 'xyz@yahoo.com');
$this->Email->settings(array('subject' => 'Hello friends'));
foreach ($myFriends AS $friend) {
$this->Email->set('someVar', $friend);
$this->Email->send(array(
'to' => $friend,
'subject' => 'Hello ' . $friend
));
}
}
}
?>
email.php
<?php
App::import('Core', 'Controller');
App::import('Component', 'Email');
class EmailTask extends Shell {
/**
* Controller class
*
* @var Controller
*/
var $Controller;
/**
* EmailComponent
*
* @var EmailComponent
*/
var $Email;
/**
* List of default variables for EmailComponent
*
* @var array
*/
var $defaults = array(
'to' => null,
'subject' => null,
'charset' => 'UTF-8',
'from' => null,
'sendAs' => 'html',
'template' => null,
'debug' => false,
'additionalParams' => '',
'layout' => 'default'
);
/**
* Startup for the EmailTask
*
*/
function initialize() {
$this->Controller =& new Controller();
$this->Email =& new EmailComponent(null);
$this->Email->startup($this->Controller);
}
/**
* Send an email useing the EmailComponent
*
* @param array $settings
* @return boolean
*/
function send($settings = array()) {
$this->settings($settings);
return $this->Email->send();
}
/**
* Used to set view vars to the Controller so
* that they will be available when the view render
* the template
*
* @param string $name
* @param mixed $data
*/
function set($name, $data) {
$this->Controller->set($name, $data);
}
/**
* Change default variables
* Fancy if you want to send many emails and only want
* to change 'from' or few keys
*
* @param array $settings
*/
function settings($settings = array()) {
$this->Email->_set($this->defaults = array_filter(am($this->defaults, $settings)));
}
}
?>
output:
PHP Warning:
SplFileInfo::openFile(/mnt/public_html/directory/web/cakephp/app/tmp/cache/persistent/directory_cake_core_file_map): failed to open stream: Permission denied in /mnt/public_html/directory/web/cakephp/lib/Cake/Cache/Engine/FileEngine.php on line 313
Warning: SplFileInfo::openFile(/mnt/public_html/directory/web/cakephp/app/tmp/cache/persistent/directory_cake_core_file_map): failed to open stream: Permission denied in /mnt/public_html/directory/web/cakephp/lib/Cake/Cache/Engine/FileEngine.php on line 313
where am i getting wrong? how do i solve this?