2012-11-27 3 views
0

cakephp 셸 cron 작업을 사용하여 대량 이메일을 보내려고합니다. 나는 한 사람에게 메일을 보내는 것으로 시작했다. 작동하지 않습니다.cakephp 대량 이메일 보내기 cron job

<?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' => '[email protected]', 
      'template' => 'test' 
     )); 
    } 

/** 
* Send just one email 
* i call this function in shell 
*/ 
    function sendMeAnEmail() { 
     //~ $this->out('Hello world.'); 
     return $this->Email->send(array( 
      'to' => '[email protected]', 
      '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('[email protected]', '[email protected]'); 
     $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))); 
    } 
} 
?> 

출력 : 다음은 내 코드입니다

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 

내가 잘못 무엇입니까? 어떻게 해결할 수 있을까요?

+0

열려는 파일에 대한 사용 권한을 확인 했습니까? – ChrisBint

+0

예 모두 쓰기 권한이 있습니다. – z22

답변

0

나는 이것이 오래 전부터 있었지만 이것이 누군가에게 도움이 될 수 있음을 알고 있습니다. tmp/cache 디렉토리에는 파일과 파일에 대한 쓰기 권한이 있어야합니다. 또한이 오류를 방지하기 위해 -R yourUser : www-data 디렉토리와 tmp/logs를 chown해야합니다. 즉, Apache에 그룹 소유권을 부여해야합니다.

아파치 웹 스페이스를/var/www /에두고 아파치 공간 밖에 코드를 갖고 싶다면 앱 디렉토리를/opt에 두는 것이 더 일반적이다.