Yii framework implements email activation [Digital Signature], yii framework

Source: Internet
Author: User

Yii framework implements email activation [Digital Signature], yii framework

The example in this article describes how to activate a mailbox in the Yii framework. We will share this with you for your reference. The details are as follows:

Controller:

// Send an email and activate the account public function actionEmail () {$ email = Yii ::$ app-> request-> get ('email '); // digital signature $ em_1 = md5 ($ email); // send $ mail = Yii: $ app-> mailer-> compose (); $ mail-> setTo ($ email); $ mail-> setSubject ("Activate email "); // publish a text with html tags $ mail-> setHtmlBody ("<a href = 'HTTP: // www.small2.com/backend/web/index.php? R = login/live & em_1 = ". $ em_1. "& email = ". $ email. "'> click this link </a>"); if ($ mail-> send () echo "success"; else echo "false"; die (); // email sending OK} // activate account public function actionLive () {$ email = Yii: $ app-> request-> get ('email '); $ em_1 = Yii: $ app-> request-> get ('em _ 1'); // echo $ em_1; die; $ em_2 = md5 ($ email ); // echo $ em_2; die; if ($ em_1 = $ em_2) {$ res = Yii: $ app-> db; $ data = $ res-> createCommand () -> update ("login", ["status" => 1], ["ema Il "=> $ email])-> execute (); if ($ data) {echo" <script> alert ('activated successfully, logged on '); location. href = 'index. php? R = login/login' </script> ";} else {echo" <script> alert ('activation failed'); location. href = 'index. php? R = login/login' </script> ";}} else {echo" <script> alert ('parameter error, reactivate '); location. href = 'index. php? R = login/login' </script> ";}}

Principle: (after registration, the original status is changed to 0 by default, and 1 after activation .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.