Shilpa Kirad
Shilpa Kirad

Reputation: 219

In yii how to send parameters to method

In yii i am creating actionEmail method using mailer extension. It will accept four parameters as FromEmail, ToEmail, Subject and Message. In order to check output i am sending hard coded values for parameters.

public function actionCreate($FromEmail='[email protected]',$ToEmail='[email protected]',$Subject='Project',$Message='Hiee')
{ 

    //using mailer extension
    $mailer = Yii::createComponent('application.extensions.mailer.EMailer');

    $mailer->IsSMTP();
    $mailer->IsHTML(true);
    $mailer->SMTPAuth = true;
    $mailer->SMTPSecure = "ssl";
    $mailer->Host = "smtp.gmail.com";
    $mailer->Port = 465;
    $mailer->CharSet = 'UTF-8';
    //$mailer->Username = "[email protected]";
    $mailer->Password = "abc";
    $mailer->From = $FromEmail;
    $mailer->FromName = "Balaee.com";
    //$mailer->AddAddress('[email protected]');
    $mailer->AddAddress($ToEmail);
    $mailer->Subject = $Subject;
    $mailer->IsHTML(true);
    //  $html = $this->renderPartial('myview',array('content'=>'Hello World'),true);
    $mailer->Body=$Message;

    if($mailer->Send()) {

        echo "Please check mail";
    }
    else {
        echo "Fail to send your message!";
    }
}

I had created this method in user controller. But its not executing. Please help me

Upvotes: 0

Views: 478

Answers (1)

Blizz
Blizz

Reputation: 8400

If you specify parameters to an action function, these define the parameters that have to be specified via either GET or POST. Normally you cannot route anything to this function unless all parameters are specified. In your case that is okay since you are assigning them default values. You should be able to call the function with the normal url format (eg index.php/?r=controller/email). Custom values can be specified with the same url: index.php/?r=controller/email&Subject=testing+email

Perhaps start by checking the error log, see if anything is outputted there. If not, I would comment out the entire function content and simply do an echo or something. This way you can at least be sure the function is called. Afterwards you can re-add the code, perhaps in pieces to see if everything remains working.

Upvotes: 2

Related Questions