Mengirim Email dengan PHPMailer di YII Framework 1
Halo, langsung saja.
  1. download extensi PHPMailer yii di https://www.yiiframework.com/extension/phpmailer
  2. Masuk ke Contoller , di controller :

public function actionCreate()

{

$model=new Register;

//$this->layout = “print2”;

// Uncomment the following line if AJAX validation is needed

// $this->performAjaxValidation($model);

if(isset($_POST[‘Register’]))

{

$model->attributes=$_POST[‘Register’];

$verivi=12345; // saya menentukan pasword user yang mendaftar.

$model->enkrip=$model->generateSalt();

$model->password=$model->hashPassword($verivi,$model->enkrip);

    if($model->email == Yii::app()->db->createCommand(‘select email from register where email like “%’.$model->email.’%” limit 1′)->queryScalar()) {

$this->redirect(array(‘email’));

    }

   

$model->namaProvinsi=$model->prov()->name;

$model->kabupatenPemohon=$model->kab()->name;

$model->kecamatanPemohon=$model->kec()->name;

$model->desaPemohon=$model->desa()->name;

$model->username=$model->noSertifikatKompetensi;

$model->awal=$verivi;

if($model->save())

    $toemail = “[email protected]”; 

                $pesan   = “Hai
Anda telah melakukan register dengan :

      Username  :”.$model->email.”

      Password  :”.$verivi; //isi email

                $cmail=$model->email;

                $email = ‘[email protected]’; //email pengirim, silahkan diganti dengan email sendiri

                $password = ‘paswordmu’; //password gmail

                $to_id = $toemail;

                $message = $pesan;

                $subject = ‘Sukses Registrasi www.hehe.org’;

                $mail = new PHPMailer;

                $mail->FromName = “No-reply [ www.hehe.org ]”;

                $mail->isSMTP();

                $mail->Host = ‘mail.hehe.com’;//masukan host email anda

                $mail->Port = 25;

                $mail->SMTPSecure = ‘tls’;

                $mail->SMTPAuth = false;

                $mail->AddCC($cmail);

                $mail->Username = $email;

                $mail->Password = $password;

                $mail->addAddress($to_id);

                $mail->Subject = $subject;

                $mail->msgHTML($message);

                $mail->send();

$this->redirect(array(‘site/login’));

}

$this->render(‘create’,array(

‘model’=>$model,

));

}

hasilnya :
sekian, semoga bermanfaat.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Scroll to Top