Saturday, 3 December 2016

How to send Mail using SMTP in Codeigniter ?

Please Find following php script for send mail using SMTP







<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class SendMail extends CI_Controller {


public function __construct()
{
parent::__construct();

$config = Array(
               'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'amit*******@gmail.com',
    'smtp_pass' => '**********',
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
}



   public function index()
{

$this->email->from('amit@example.com', 'Amit Chouhan');
$this->email->to('to@gmail.com ');
$this->email->cc('cc@gmail.com');


$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

}



}
?>

Email preferences are available at
https://www.codeigniter.com/user_guide/libraries/email.html



Thursday, 27 October 2016

How to Remove Visual Composer's shortcodes from the Post Content ?




As we need to remove Visual Composer's shortcodes from the Post Content , we need to follow the below steps -

1. put the following code in functions.php

functions.php
function get_the_post_content($postdata='')
{
$postdata1 = strip_tags(do_shortcode($postdata));
$postdata1 = trim(preg_replace('/\s+/',' ', $postdata1 ));
return $postdata1;
}


2. you can get the post content on any page by integrating the below code
page.php


<?php if( have_posts() ):

         while( have_posts() ): the_post();
         the_title(); // showing post title

echo get_the_post_content($post->post_content); // post content

or

echo get_the_post_content(get_the_content()); // post content

endwhile;
 endif; wp_reset_query(); ?>

Wednesday, 14 September 2016

How to read excel file without uploading on server

The following code includes three columns namely as " name , contact , email " as shown the below screenshot



index.php



<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="row">
  <div class="col-lg-2">
  </div>
                <div class="col-lg-8">
                    <div class="panel panel-default">
                       
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
                                   
                                    <tbody>
                                       
<tr>
                                            <th>Read Excel</th>
<td>
<input type="file" name="file"/> 
</td>
</tr>
<tr>
                                            <th></th>
<td>
<input type="submit" value="Upload"/>
</td>
</tr>
                                            
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
             <div class="col-lg-2">
  </div>
            </div>
</form>




upload.php


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Read Excel File</title>

</head>
<body>

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';



// This is the file path to be uploaded.
//$inputFileName = 'discussdesk.xlsx'; 
$inputFileName=$_FILES["file"]["tmp_name"];



try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}


$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);  // Here get total count of row in that Excel sheet
?>
<table>
<tr>
<th>Name</th><th>Contact</th><th>Email</th>
</tr>
<?php

for($i=2;$i<=$arrayCount;$i++){
$name = trim($allDataInSheet[$i]["A"]);
$contact=trim($allDataInSheet[$i]["B"]);
$email=trim($allDataInSheet[$i]["C"]);

?>
<tr>
<td><?php echo $name; ?></td>
<td><?php echo $contact; ?></td>
<td><?php echo $email; ?></td>
</tr>
<?php

}

?>
</table>
<body>
</html>


you can also download the zip file of the above code..







Wednesday, 31 August 2016

How To Type Hindi in HTML page

Here The  code for hindi typing into a HTML tag..





<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="https://www.google.com/jsapi">
    </script>
    <script type="text/javascript">

      // Load the Google Transliterate API
      google.load("elements", "1", {
            packages: "transliteration"
          });

      function onLoad() {
        var options = {
            sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
            destinationLanguage:
                [google.elements.transliteration.LanguageCode.HINDI],
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
        };

        // Create an instance on TransliterationControl with the required
        // options.
        var control =
            new google.elements.transliteration.TransliterationControl(options);

        // Enable transliteration in the textbox with id
        // 'transliterateTextarea'.
        control.makeTransliteratable(['transliterateTextarea']);
control.makeTransliteratable(['transliterateTextarea2']);
      }
      google.setOnLoadCallback(onLoad);
    </script>
  </head>
  <body>
    Type in Hindi (Press Ctrl+g to toggle between English and Hindi)<br>
    <textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea>
<input type="text" id="transliterateTextarea2" name="sunil">
  </body>
</html>





Friday, 11 December 2015

Show clock using PHP

Show Current Time On Webpage Using PHP with Javascript 

Timer Function:-

<script type="application/javascript">
function ajaxcall(){
     $.ajax({
         url: 'getTime.php',
         success: function(data) {
             data = data.split(':');
             $('#hours').html(data[0]);
             $('#minutes').html(data[1]);
             $('#seconds').html(data[2]);
         }
     });
 }



setInterval('ajaxcall()',1000);

</script>




gettime.php

<?php    
date_default_timezone_set('Asia/Calcutta');
echo $date = date('h:i:s A'); 
?>



Friday, 28 August 2015

How to upload large amount of data within seconds into mysql database USING csv file



Using this php script you can upload thousands of  record  within a second

1. HTML form for upload csv file -

<form name="import" method="post" enctype="multipart/form-data">
        <input type="file" name="file" /><br />
        <input type="submit" name="submit" value="Submit" />
    </form>




2. PHP Script FOr Execution -
<?php
    $con = mysql_connect('localhost','root','123456'); //database Connections
if(!$con){die(mysql_error());
}
else
{
mysql_select_db('test',$con);
}

   
    if(isset($_POST["submit"]))
    {
$status=2;       
  move_uploaded_file($_FILES["file"]["tmp_name"],
      "/var/www/html/importviaexcel/upload/" . $_FILES["file"]["name"]);
      $file_path="/var/www/html/importviaexcel/upload/" . $_FILES["file"]["name"]; //file & folder name Where csv uploaded

echo "My file - ".$file_path;
$table="csv";
$fp = file("$file_path");
$total_count=count($fp);
echo "Total record - ".count($fp);
$sql_load =     " LOAD DATA INFILE '".$file_path."'" . 
            "IGNORE INTO TABLE " . $table . 
            " FIELDS TERMINATED BY " . "','" . 
            // " LINES TERMINTED BY " . "\r\n" . 
            " IGNORE 1 LINES
            ( @no,@name,@mobile,@email)
            set
            no = @no,
            name = @name,
            mobile = @mobile,
            email = @email,
            status = '2' 
            ";


$result = mysql_query($sql_load, $con);

$upload_rec=mysql_affected_rows();
$duplicate=$total_count-$upload_rec;
echo "Total - $total_count </br>Upload - $upload_rec </br> duplicate - $duplicate  ";
           

    }
?>




  Hope it will Helpful for you.

Wednesday, 15 July 2015

Remove file extension from url using htaccess ?

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

How to get Duplicate Record From Mysql Database ?

Use this query to get duplicate record-

SELECT mobile, count(id) as total_count FROM servicecall
GROUP BY mobile HAVING total_count > 1

Wednesday, 8 July 2015

How to set multiple google maps on single web page using javascript ?

script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>


<script type="text/javascript">
// Enable the visual refresh
google.maps.visualRefresh = true;
// Set the Map variable
var map;
var infowindow = new google.maps.InfoWindow();
function initialize() {
var myOptions = {
zoom: 8,
mapTypeControl: true,
scrollwheel: true,
streetViewControl : true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles:[
{ featureType: "water", stylers: [ { color: "#8DC4E1", hue: 0.1 } ] },
{ featureType: "landscape.natural", stylers: [ { color: "#F4F3EF", lightness: +100 } ] },
{ featureType: "road.local", stylers: [ { color: "#FFF" } ] }
],
};
var all = [
["4605 S Tamiami Trail, Sarasota, FL 34231, USA", "27.287359", "-82.530634"],
["8519 state road 70 east bradenton fl 34211", "27.439685", "-82.452375"],
];
var infoWindow = new google.maps.InfoWindow;
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
map1 = new google.maps.Map(document.getElementById('map_canvas1'), myOptions);
// Set the center of the map
var pos = new google.maps.LatLng(27.287359, -82.530634);
var pos1 = new google.maps.LatLng(27.439685, -82.452375);
map.setCenter(pos);
map1.setCenter(pos1);
function closeinfocallback(infowindow)
{
return infowindow.close();
}
function infoCallback(infowindow, marker,map)
{
return function() {
infowindow.open(map, marker);
};
}
function setMarkers(map, all,i)
{

var name = all[i][0];
var lat = all[i][1];
var lng = all[i][2];
var latlngset;
latlngset = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: latlngset,
map: map,
});
var content = '<div class="map-content"><h3>' + name + '</h3></div>';
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(content);
google.maps.event.addListener(marker, 'click', infoCallback(infowindow, marker,map));

}
// Set all markers in the all variable
setMarkers(map, all,'0');
setMarkers(map1, all,'1');
}
// Initializes the Google Map
google.maps.event.addDomListener(window, 'load', initialize);
</script>




<div id="map_canvas1" style="height: 300px; width: 100%;">  </div>

<div id="map_canvas" style="height: 300px; width: 100%;">  </div>

Tuesday, 7 July 2015

How to send mail using PHP ?

You can use this Script to send mail !

$headers = "From: Company name<info@domainname.com>\r\n" .
"Reply-to: Customer<info@domainname.com>\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$subject="Service Invoice";

$to ="amit******@gmail.com";
mail($to,"Subject","Test Mail" ,$headers);