php - Send email to single user in loop -


i trying send bulk email php yii . , using yii extension smtpmail. problem when selecting more 1 recipient. sending email . mean adding in "to". if using simple mail function working . , email going individuals. here code

$sent=$this->sendbulkemail($inv->to_email,usermodule::t("invitation {site_name}",array('{site_name}'=>yii::app()->name)),usermodule::t($template,array('{msg}'=>$msg,'{link}'=>$link))); 

and email function

public function sendbulkemail($email,$subject,$message)     {         $adminemail = yii::app()->params['adminemail'];         $message = wordwrap($message, 70);         $message = str_replace("\n.", "\n..", $message);        // $mail2 = new phpmailer(); // create new object          $mail=yii::app()->smtpmail;         $mail->setfrom($adminemail, 'goal surf');         $mail->subject = '=?utf-8?b?'.base64_encode($subject).'?=';         $mail->msghtml($message);         $mail->addaddress($email, "");         $mail->smtpsecure = 'tls';          $mail->send();         unset($mail);     }  

but if using simple mail() working fine.

$sent=mail($inv->to_email,usermodule::t("invitation {site_name}",array('{site_name}'=>yii::app()->name)),usermodule::t($template,array('{msg}'=>$msg,'{link}'=>$link)),$headers); 

anybody please tell me how .

update enter image description here

i have solved issue . need use $mail->clearaddresses(); clear addresses after email success .

public function sendbulkemail($email,$subject,$message)     {         $adminemail = yii::app()->params['adminemail'];         $message = wordwrap($message, 70);         $message = str_replace("\n.", "\n..", $message);        // $mail2 = new phpmailer(); // create new object          $mail=yii::app()->smtpmail;         $mail->setfrom($adminemail, '');         $mail->subject = '=?utf-8?b?'.base64_encode($subject).'?=';         $mail->msghtml($message);         $mail->addaddress($email, "");         $mail->smtpsecure = 'tls';         $mail->send();         $mail->clearaddresses();     } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -