Yii SMTP Mail Extension

I created one extension to sent the mail using smtp methos. Just add it into your yii project and configure in main.php and send mail.

Download And Add SMTP Extension

Please Download the smtp mail extension and add it into protected/extension folder.
SMTP Mail Extension


SMTP Details in config/main.php

After added smtpmail extension file into extension folder, We have to give the set of details like Hostname, Username, Password, Mailer option, Port and SMTPAuth. We must have to configure this details in main.php before send the mail using this extension. I added the code below

'components'=>array(
        'Smtpmail'=>array(
            'class'=>'application.extensions.smtpmail.PHPMailer',
            'Host'=>"mail.yourdomain.com",
            'Username'=>'test@yourdomain.com',
            'Password'=>'test',
            'Mailer'=>'smtp',
            'Port'=>26,
            'SMTPAuth'=>true, 
        ),
),

SMTP Mail Function

Using this function we can send the mail using smtp details.

public function mailsend($to,$from,$subject,$message){
        $mail=Yii::app()->Smtpmail;
        $mail->SetFrom($from, 'Publicfinance.in');
        $mail->Subject    = $subject;
        $mail->MsgHTML($message);
        $mail->AddAddress($to, "");
        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        }else {
            echo "Message sent!";
        }
    }