public function repMails($email, $id) { //получаю шаблон письма $sms = Mails::model()->findByPk(1); if ($sms) { //вставляю тело $html = $sms['body']; //тема $subject = $sms['theme']; //нахожу нужный купон $coupon = Coupon::model()->findByPk($id); //название купона $product = $coupon['title']; //скидка $sale = $coupon['discount']; //цен до скидки $before = $coupon['discountPrice'] . " рублей"; if ($before == 0) { $before = "Не ограничена"; $after = "Не ограничена"; } else { //цена после скидки $after = round($before - $sale * $before / 100, 2); $after .= " рублей"; } //ссылка на купон $link = $_SERVER['HTTP_HOST'] . Yii::app()->createUrl("/coupon", array('id' => $coupon['id'], 'title' => $coupon['title'])); $link = "<a href='http://" . $link . "'>" . $link . "</a>"; //подставляю в шаблон $html = str_replace('[product]', $product, $html); $html = str_replace('[before]', $before, $html); $html = str_replace('[after]', $after, $html); $html = str_replace('[sale]', $sale, $html); $html = str_replace('[link]', $link, $html); //отправляем письмо $this->sendMail($email, $subject, $html); } }