How to send mass email based on categories of Users?


(nebrom) #1

I am new for yii2, I am developing web application that sends alerts to user based on their desired categories:
i want to send list of titles with a link to users
**tender is a table with id ,title , detail.bidstatus
i am trying to send the list of tenders to a user or users
//i tried the following codes but not showing the list of tenders
public function sendEmail($email)
{

		           $tenderstatus='Open';
					   
				 $bids=Tenderlist::find()
				  ->andFilterWhere(['bidstatus'=>$tenderstatus,]);


    return Yii::$app->mailer->compose()
        ->setTo($email)
        ->setFrom([$this->email => $this->name])
        ->setSubject($this->subject)
        //->setTextBody($this->body)
        ->setHtmlBody($bids)
        ->send();
}

(Alexander Makarov) #2
  1. Select all users with a certain category.
  2. foreach.
  3. Form and send email.

(nebrom) #3

could please try it?, i just modified the question to get the basic knowledge


(Alexander Makarov) #4

That won’t work like that.

 $bids=Tenderlist::find()
				  ->andFilterWhere(['bidstatus'=>$tenderstatus,]);

You’re missing ->all() at the end.

 ->setHtmlBody($bids)

$bids are not HTML, they are data. You need to form HTML from it first.