How to send email by using phpmailer

php

Posted on 13 Feb 15 by Vickey
  446

First Download phpmailer.zip and extract it now include it in your file

require_once(APP_ROOT_PATH.'/PHPMailer/class.phpmailer.php');

now create a function

 function sendEmail($receiptEmail,$senderEmail,$cc,$subject,$message)
     //function sendEmail($receiptName, $receiptEmail, $subject, $message, $senderEmail='test@gmail.com', $senderName='test')
    { 
    $subject = utf8_decode($subject);
    $senderName='Welcome';
      $mail = new PHPMailer();
      $mail->IsSMTP(); 
      $mail->SMTPAuth   = true; 
      $mail->SMTPSecure = "ssl";  
      $mail->Host       = "smtp.gmail.com"; 
      $mail->Port       = 465;                
      $mail->Username   = "example@gmail.com";
      $mail->Password   = "example@12345";            
      $mail->SetFrom("$senderEmail", "$senderName"); 
      $mail->Subject    = $subject; 
      $mail->Body       = $message;
      $mail->IsHTML(true);
      $mail->AddAddress($receiptEmail, $receiptName);
      return $mail->Send();
    }

and now you call it where you want to send email

How to validate url in php

php

Posted on 13 Feb 15 by Vickey
  430

Create a function

function isValidURL($url)
    {
        return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
    }

and use it as

$url='www.example.com';
isValidURL($url);

How to validate email in php

php

Posted on 13 Feb 15 by Vickey
  370

We can validate email by using eregi function by giving our email pattern

function isValidEmail($email)
{
        $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
        if (eregi($pattern, $email))
         return true;
        else 
         return false;
 }

and you can call it

$email='example@gmail.com';
if(isValidEmail($email)){

 // do something..................

}

 

How to generate word document in yii

Yii

Posted on 11 Feb 15 by Vickey
  1133

Create a action in your controller

public function actionUserDetails() {


   $title = "My Profile";
   $view= $this->renderPartial('profile', array('title'=>$title), true);
   header("Pragma: no-cache");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: private", false);
   header("Content-type: application/vnd.ms-word");
   header("Content-Disposition: attachment; filename=\"test.doc");
  header("Content-Transfer-Encoding: binary");
  ob_clean();
  flush();
  echo $view;
  Yii::app()->end();


}

create profile.php in your view directory and add your data

Now create link for create word file on your view file

echo CHtml::link('Download Report', array('User/UserDetails'));

 

How to install yii2 on ubuntu system with xampp

Yii

Posted on 07 Feb 15 by Vickey
  1929

If you have ubuntu system and want to install yii2 then folllow these below process

First we need to install composer so we will install composer by this command

curl -sS https://getcomposer.org/installer | php

or if we did not install php globally

curl -sS https://getcomposer.org/installer | /opt/lampp/bin/php

when composer will be installed we need to make it globally so we will run this command

sudo mv composer.phar /usr/local/bin/composer

Now move to your local host root folder

cd /opt/lampp/htdocs/

when you will in root run this command

composer create-project --prefer-dist yiisoft/yii2-app-basic

or

/usr/local/bin/composer create-project --prefer-dist yiisoft/yii2-app-basic

now if can see basic filder in your web root folder

you can run it by url

localhost/basic/web/

Thanks

How to redirect on last page in laravel

Laravel

Posted on 31 Jan 15 by Vickey
  492

By using redirect back function we can redirect on last page in laravel

return Redirect::back();

 

How to use role management in laravel

Laravel

Posted on 31 Jan 15 by Vickey
  810

By using laravel packages we can manage user roles. but we can create a custom code to manage roles by using route file. For example if i am creating a function only access for admin then i can add a conditions in my routing

if(Auth::user()){

    if(Auth::user()->role_id==1){

        Route::get('/manageusers', 'AdminController@manageusers');
    }
    else {

           Route::get('/manageusers', function(){
           return Redirect::to('/');  });
    }
}

In this code user's role id is 1 then manageusers function can accessed otherwise it will redirect to home page

How to install laravel on ubuntu server

Laravel

Posted on 30 Jan 15 by Vickey
  784

For install laravel we need install composer first.Open your ubuntu terminal and type the following commands.

curl -s https://getcomposer.org/installer | /opt/lampp/bin/php

it will download composer.phar to /home/yourcomputername

now move composer to usr/local/bin or run cmd

sudo mv composer.phar /usr/local/bin/composer

run this command on terminal

/opt/lampp/bin/php  composer.phar it will install composer

after complete the process Insatll Laravel by these steps

  1. Download laravel

  2. extract it and move it in htdocs folder

  3. Open terminal and go in the laravel folder

    cd /opt/lampp/htdocs/laravel
  4. when you are in laravel folder run this command

/opt/lampp/bin/php /usr/local/bin/composer.phar install

after complete process run

 /opt/lampp/bin/php /usr/local/bin/composer.phar update

Done

populate dropdown from a php array

php

Posted on 30 Jan 15 by Vickey
  519
function arraySelectBox($id, $controlName='', $arrayToFill='', $selected='', $helpText='',$eventFunction='', $cssClass='', $makeDisable='')
{   

    if($controlName=='')
        $controlName = $id;

    if($cssClass!='')
        $cssClass = 'class=$cssClass';

    $selectBox .=  '<select name="$controlName">';
    if($helpText!='')
    $selectBox .= '<option value="0">$helpText</option>';
    else
    $selectBox .= '<option value="0">Select An Option</option>';
    foreach($arrayToFill as $key =&gt; $value)
    {
        if($selected==$key)

            $selectBox .= '<option selected="selected" value="$key">$value</option>';
        else
            $selectBox .= '<option value="$key">$value</option>';
    }

    $selectBox .= '</select>';
    return $selectBox;
}
arraySelectBox($id, $controlName='', $arrayToFill='', $selected='', $helpText='',$eventFunction='', $cssClass='', $makeDisable='');

 

Populate a dropdown by fetching data from database

php

Posted on 30 Jan 15 by Vickey
  446

If you are creating a dynamic dropdown which options should come from database. For this you can use the below code. In the below function you can pass table name fields which you want set as option values and options text and you can give database conditions also

Here is instructions for parameters

id :  this will be the dropdown id

tableName : this is table name from which you want to fetch data

fieldText : your datbase table field which you want to show as option text

whereCondition : if you want to fetch data by using a condition you can give condition

Here are also parameter for add events also like 'onchange' 

echo selectBox($id, $tableName,$fieldText, $fieldValue, $whereCondition='', $orderBy='', $eventFunction='', $defaultValue='', $helpText='', $disable='', $width='', $controlName='', $printQuery=0, $cssClass='',$addtionItems='');
public function selectBox($id, $tableName,$fieldText, $fieldValue, $whereCondition='', $orderBy='', $eventFunction='', $defaultValue='', $helpText='', $disable='', $width='', $controlName='', $printQuery=0, $cssClass='',$addtionItems='')
{   

    if($controlName=='')
    $controlName = $id;

    if($cssClass!='')
    $cssClass = "class=$cssClass";

    if($eventFunction!='')
    $eventFunctionOnChange = " onchange='$eventFunction'";

    $selectBox .=  "";
    return $selectBox;
}

Please feel free to write a comment

Thanks

www.000webhost.com