Email Just Send to First User in Array (Not All UserUser)


I want to send email to all user in database table users. but the error is:

the email just send to first user in array

this is EmailTemplatesController.php

public function admin_send_notification() {

	$adminEmailData = $this->User->find('first', array('conditions' => array('' => 313)));
	$email = $this->User->find('all', array('fields'=>array('email'), 'conditions' => array('User.role_id' => 2)));
	$adminEmailFrom = $adminEmailData['User']['email'];	


function app_update_notification($email, $slug, $adminEmailFrom) {	
	$recipients = array("", "");
	//$to      		= 	implode(',', $recipients);
	foreach ($email as $to) {
		# code...
	$from    		= 	$adminEmailFrom;
//	debug($to);die;
	$mail_message 	= 	'';	
	$emailTemplate 	= 	$this->EmailTemplate->find('first', array('conditions'=>array('EmailTemplate.slug'=>$slug)));
	$subject 	= 	$emailTemplate['EmailTemplate']['subject'];
	$mailMessage = str_replace(array('{NAME}','{SITE}'), array(Configure::read('Site.title')), $emailTemplate['EmailTemplate']['description']);
	$Template = 'default';		  
	parent::__sendMail($to['User']['email'], $subject, $mailMessage, $from ,$Template);
	$this->Session->setFlash("Email has been send",'admin_flash_good');
	$this->redirect(array('controller'=>'email_templates', 'action'=>'index'));

this is AppController.php

public function __sendMail($To, $Subject, $message, $From, $template = 'default', $smtp = 1, $attachment = array() ) {
	App::uses('CakeEmail', 'Network/Email');
	// echo $smtp;die;
	$email  = 	new CakeEmail();
    $email->attachments($attachment) ;
    $email->layout 	= 	'default';
	if ($email->send($message)) {
	    return true;
    } else {
	    return false;


$email = $this->User->find(‘all’, array(‘fields’=>array(‘email’), ‘conditions’ => array(‘User.role_id’ => 2)));

use for each after this.


or use ->toArray(),

if you have many users its good ideia also check the server rules for maximum number of $recipients per mail and the maximum number of mails sent per hour


I have used foreach in the code: foreach ($email as $to)


Previously i have try to send email to all user in database, the website is running normally, but suddenly there are so much errors with detail below:

write failed: No space left on device
unserialize(): Error at offset 4069 of 4085 bytes
_cake_core_ cache was unable to write 'cake_dev_id' to File cache

is that caused the error?