send email in yii

hi all,

 how can i send email in  yii.

Thank you.

Hi. Yii haven’t is own mail service. Use native mail() function.

There are extensions that help send emails using variuos methods like smtp.

Look here http://www.yiiframework.com/extensions/?category=9

This is the controller action for the contact form:


public function actionContact() {

        $model = new ContactForm;

        if (isset($_POST['ContactForm'])) {

            $model->attributes = $_POST['ContactForm'];

            if ($model->validate()) {

                $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';

                $subject = '=?UTF-8?B?' . base64_encode('[supporto] ' . $model->subject) . '?=';

                $headers = "From: $name <{$model->email}>\r\n" .

                        "Reply-To: {$model->email}\r\n" .

                        "MIME-Version: 1.0\r\n" .

                        "Content-type: text/plain; charset=UTF-8";


                mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);

                Yii::app()->user->setFlash('contact', 'Message send');

                $this->refresh();

            }

        }

        $this->render('contact', array('model' => $model));

    }