php - Send Mail to Multiple Address in Cakephp 3 : Cannot modify an existing config -
i trying send email multiple recipient address in cake php 3.
my codes :
$this->loadmodel('asindividualdetails'); $emaildetails = $this-> asindividualdetails->find('all',['fields'=>'email']); $emaildetails = $emaildetails->toarray(); foreach ($emaildetails $key => $a) { $this->loadmodel('domainemaildetails'); $domainemaildetails = $this-> domainemaildetails->find('all')->first(); $domainemaildetails = $domainemaildetails->toarray(); $host = 'ssl://'.$domainemaildetails['host_name']; $username = $domainemaildetails['user_name']; $password = $domainemaildetails['user_password']; $port = $domainemaildetails['port']; $email_to = $a['email']; $sendername = 'abc'; $email_id ='xyz110@gmail.com'; email::configtransport('webmail', [ 'classname' => 'smtp', 'host' => $host, 'port' => $port, 'timeout' => 30, 'username' => $username, 'password' => $password, 'client' => null, 'tls' => null, ]); ////////// send mail $email = new email('webmail'); $email ->template('default','default') ->emailformat('both') ->from([$username => $sendername]) ->to($email_to) ->replyto($email_id) ->subject('client message'); $response = $email->send('my msg'); if($response){ echo 'success'; }else{ echo 'failed'; } }
when run script 1 mail send , after error has come :
cannot modify existing config "webmail"
how solve error , send mail recipient mail address.
make email configuration outside of loop. don't want try , establish configuration every time send emails - 1 time. send emails based on 1 configuration.
Comments
Post a Comment