0

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?

4

1 回答 1

0

我知道这是很久以前的事了,但这可能会对某人有所帮助。您的 tmp/cache 目录应该对其以及其中的文件具有写入权限。您还应该 chown -R yourUser:www-data 该目录和 tmp/logs 以防止此错误,即将组所有权授予 Apache。

顺便说一句,如果你想让你的代码在 Apache 空间之外,将你的 Apache webspace 放在 /var/www/ 中并做一些事情,比如把你的应用程序目录放在 /opt 中是更常见的。

于 2017-02-03T17:29:35.510 回答