문제

I want to send an email with CakeEmail to multiple addresses (email address of the people who sign up in my website).

Here is my code I use :

public function send($d){
    $this->set($d);
    if($this->validates()){
        App::uses('CakeEmail','Network/Email');

        $users = $this->User->find('all');

        $this->set($tests);
        foreach($users as $user)
        {
            $tests .= '"'.$user['User']['email'].'",';
        }

        $mail = new CakeEmail();
        $mail
            ->to(array($tests)) 
            ->from(array('test2@test.fr' => 'Hello'))
            ->subject('ALERTE')
            ->emailFormat('html')
            ->template('ouverture')->viewVars($d);
            return $mail->send();

        }

    else{
        return false;
    }

    }

And here's my error :

Invalid email : ""test@test.com","test@test.fr","
도움이 되었습니까?

해결책

Try

$tests = array();
foreach($users as $user)
{
    $tests[] = $user['User']['email'];
}

$mail = new CakeEmail();
$mail->to($tests) 
     ->from(array('test2@test.fr' => 'Hello'))
     ->subject('ALERTE')
     ->emailFormat('html')
     ->send('Your message here');

다른 팁

Try

$mail = new CakeEmail();

foreach($users as $user) {
    $mail->addTo($user['User']['email']);
}

$mail->from(array('test2@test.fr' => 'Hello'))
     ->subject('ALERTE')
     ->emailFormat('html')
     ->template('ouverture')->viewVars($d);
return $mail->send();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top