arrays - Yii2 - mailer - send message to email rows in database -


greetings,

i need send email several recipients stored in table named mail has field called email.

in controller created action query table mail emails.

later tried use implode() function separated comma, didn't work because of mailer policies. generated wrong format -> "email1@mail.com, email2@mail.com, email3@mail.com".

tried each loop , serialize() function without success.

the json_encode() function close need, separate array of emails -> "email1@mail.com", "email2@mail.com", "email3@mail.com". appends field name before value , not accepted mailer policies.

so far i'm stuck following code:

public function actionsucesso() {     $query = new query;     $query->select('email')     ->from('mail');     $command = $query->createcommand();     $enderecos = $command->queryall();      $enviar = json_encode($enderecos);      yii::$app->mailer->compose()         ->setfrom('atf@website.com')         ->setto($enviar)         ->setsubject('oferta de jogo no site da atf.')         ->settextbody('aceda em: http://atf.besaba.com/index.php?r=playschedule%2findex2')         ->send();     return $this->render('sucesso'); } 

i think in order mailer work , send message correct format needs be: ->setto("mail1@mail.com", "mail2@mail.com", "mail3@mail.com")

is there way of solving problem? many in advance.

to array of email numeric indexes call queryall() method $fetchmode parameter \pdo::fetch_column, , pass returned array mailer's setto() method.

$enderecos = $command->queryall(\pdo::fetch_column);  //$enviar = json_encode($enderecos); <- line no needed  yii::$app->mailer->compose()     ->setfrom('atf@website.com')     ->setto($enderecos) //you pass array of email addresses     ->setsubject('oferta de jogo no site da atf.')     ->settextbody('aceda em: http://atf.besaba.com/index.php?r=playschedule%2findex2')     ->send(); 

see queryall() documentation , list of pdo constant including available fetch modes starting pdo::fetch_. assuming using yii2 default mailer, swiftmailer documentation how set recipients


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -