How will you read your Inbox messages using PHP script ?


Introduction

In my previous post i talked about “How to create your own helper file to generate PDF in PHP(CodeIgniter)?”. In some application may require you to code to read your email. If you are wondering “How to read your inbox messages using PHP script?”, then you are at right place. In this short article we will discuss about how to read messages from Gmail inbox using php script. We will make use of IMAP to read GMail inbox messages.

We will create a php file naming GmailReader.php and paste below code.

Below compact code to read email from your gmail account.



function readMail() {

    $dns = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
    $email = "Your Mail";
    $password = "Password";

    $openmail = imap_open($dns,$email,$password ) or die("Cannot Connect ".imap_last_error());
    if ($openmail) {

        echo  "You have ".imap_num_msg($openmail). " messages in your inbox";

        for($i=1; $i <= 100; $i++) {

            $header = imap_header($openmail,$i);
            echo "
"; echo $header->Subject." (".$header->Date.")"; } $msg = imap_fetchbody($openmail,1,"","FT_PEEK"); /* $msgBody = imap_fetchbody ($openmail, $i, "2.1"); if ($msgBody == "") { $portNo = "2.1"; $msgBody = imap_fetchbody ($openmail, $i, $portNo); } $msgBody = trim(substr(quoted_printable_decode($msgBody), 0, 200)); */ echo $msg; imap_close($openmail); } else { echo "Failed reading messages!!"; } }

That's all. We are done. Now run your GmailReader.php file from the browser and can see the results.

I am able to read gmail inbox using above code. Hope this post helps. Please consider sharing with friends, like the post, that way it will be helpful for others too. Keep visiting.

Create your own helper file to generate PDF in PHP(Codeigniter)


  How to write your own helper file to export grid as PDF in PHP?

                     In my previous post was about “How to generate PDF using PHP”. Today I am writing my own helper file for PDF generation. If you are wondering “How to create your own helper file to generate PDF in PHP(Codeigniter) ?” , Then solution is here. Here I have created single helper file for PDF to export any grid. All you need to do is, you just have to call my helper file and pass your datas as parameter into the function, That’s all done. It will generate PDF as well as you can print PDF file. By doing this you can reuse your code and you don’t have to write much lines of codes. So let’s follow steps to do this stuffs,

 

Step 1:

Download files from dom-pdf and m-pdf and extracts it into your helper folder, ie: /system/helpers/dompdf (or mpdf ).

Step 2:

Now create your own helper and name it pdfexport_helper.php and paste the below lines of code. If you are using mpdf then use below code.




/*
* Subject          : Export pdf using mpdf
* Author           : Sanjoy Dey
* @Created Date    : 10-02-2012
* Version          : CodeIgniter_2.0.3
*
*/

if ( ! function_exists('exportMeAsMPDF')) {

    function exportAsMPdf($htmView, $fileName) 
    {

        $CI =& get_instance();
        $CI->load->library('mpdf51/mpdf');
        // $CI->mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
        $CI->mpdf->AliasNbPages('[pagetotal]');
        $CI->mpdf->SetHTMLHeader('{PAGENO}/{nb}', '1',true);
        $CI->mpdf->SetDisplayMode('fullpage');
        $CI->mpdf->pagenumPrefix = 'Page number ';
        $CI->mpdf->pagenumSuffix = ' - ';
        $CII->mpdf->nbpgPrefix = ' out of ';
        $CI->mpdf->nbpgSuffix = ' pages';
        $CI->mpdf = new mPDF('', 'A4', 0, '', 12, 12, 10, 10, 5, 5);
        $style = base_url().'/source/template/css/stylesheet.css';
        $stylesheet = file_get_contents( $style);
        $CI->mpdf->WriteHTML($stylesheet,1);                       
        $CI->mpdf->WriteHTML($htmView,2);                       
        $CI->mpdf->Output('mpdf.pdf','I');
     }
  }

If you are using dompdf then use below code.

 
  
/*
* Subject          : Export pdf using dompdf
* Author           : Sanjay
* Version          : CodeIgniter_2.0.3
*/

if ( ! function_exists('exportMeAsDOMPDF')) {

     function exportAsDomPdf($htmView, $fileName) 
     {

         $CI =& get_instance();
         $CI->load->helper(array('dompdf', 'file'));
         $CI->load->helper('file');
         $pdfName = $fileName;
         $pdfData = pdf_create($htmView, $pdfName);
         write_file('Progress Repost', $pdfData);   
     }
}

?>
 
 
Step 3:

Open your controller page and inside your function write below code.



 #Export Function goes here#
 /*This Function is used for Exporting Pdf
  * Author : Sanjay
  */

  $this->load->helper(‘pdfexport_helper.php’);
  $urlId  = $this->uri->segment('3');

    if($urlId == "export") {

       $data['pageTitle'] = "Annual Report";
       $data['htmView'] = $this->load->view('annualreport_view',$data,TRUE);
       $templateView  = $this->load->view('../template_export',$data,TRUE);
       exportAsMPdf($templateView,$data['filename']);     
          OR          
       exportAsDomPdf($htmView,$fileName)                                                                 
    }

/* Export Pdf END here */

Step 4:

That’s all you have done all steps. Click in export button to export to PDF and enjoy.

Hope this post will help you a lot to reuse your code and creating your own helper file to generate PDF in PHP(Codeigniter).

Post your queries if you have and share. Keep visiting for new posts here. All the best. Have a good day.

You also can join my group for latest technology updates in below link,

How to generate pdf in PHP ?


  How to export grid data’s as PDF using PHP (Codeigniter)?

                   
  Today I have a new article for you all here. In my last post you saw major difference between ASP & ASP.NET. Today I am going to show you how to export grid datas as PDF using php. There is lots of plug-ins available to generate PDF in PHP. Here I am going to show you two best PDF generator which I used for my professional field.  I am well versed with dom-pdf and m-pdf. These two PDF generators really great I found compare to other. So here I am going to show you  “ How to export grid data as PDF in PHP ? “  
All you have to do first is you have to download dom-pdf or m-pdf zip files. If you are wondering where can you get the zip files then here is the links to download dom-pdf and m-pdf.  These are the steps you need to follow to generate PDF using dompdf and mpdf.
        Step 1:
                After downloading the zip files just extract it.  You’ll get a folder (I renamed it “dompdf” / “mpdf”), and put the whole thing into your helper folder, ie: /system/helpers/dompdf
       Step 2:
              Create plug-in for the dompdf. I have created plug-in and named it dompdf_helper.php and write below lines of code inside the file.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function 
pdf_create($html$filename=''$stream=TRUE
{
    
require_once("dompdf/dompdf_config.inc.php");
    
    
$dompdf = new DOMPDF();
    
$dompdf->load_html($html);
    
$dompdf->render();
    if (
$stream{
        $dompdf
->stream($filename.".pdf");
    
else {
        
return $dompdf->output();
    
}
}
?> 
Or



<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function 
pdf_create($html$filename=''$stream=TRUE
{
   require_once("dompdf/dompdf_config.inc.php");    spl_autoload_register(“DOMPDF_autoload”);   
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream{
        $dompdf
->stream($filename.".pdf");
    
else {
        
return $dompdf->output();
    
}
}
?>
          For m-pdf extracted folder into your library folder.

Step 3 :
            That’s it you have done almost. Now to call your dompdf helper file use a function in your controller to generate PDF file. Here is the code you need to write,
  <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

  function exportPDF() {
     $this->load->helper(array('dompdf''file'));
     
// page info here, db calls, etc.     
     
$html $this->load->view('controller/viewfile'$datatrue);
     
pdf_create($html'filename');
     or
     
$data pdf_create($html''false);
     
write_file('name'$data);
     
//if you want to write it to disk and/or send it as an attachment   
   }
Or
    /* You can write your function like this also if you have separate view file to generate pdf */
function exportPDF() {
$year = $this->input->post(“currentyear”);
$monthname = $this->input->post(“month”);
$data[‘reportList’] = $this->pdfgenerator_model->getpdfDetails($id,$month,$year);
$dataView = $this->load-> view(‘pdf/report’,$data,true);
$this->load->helper(array('dompdf''file'));
$this->load->helper('file'));
      $pdfName = $monthname.”-”.$year.” 'Report'”;
      $pdfData = pdf_create($dataView,$pdfName);
      Monthnamewrite_file('My Monthly Report' ,$pdfData);
}    
?>
And If you want to use mpdf then it’s easy to generate. Here is the line of code to generate PDF using mpdf.
<?php
function generatePdf() {
$this->load->library(“mpdf51/mpdf”);
$data[‘reportList’] =$this->pdfgenerate_model ->getDetails();
$htmview = $this->load-> view(“pdfview”,$data,true);
$CI->mpdf = new mPDF('', 'A4', 0, '', 12, 12, 10, 10, 5, 5);
$this->mpdf->WriteHTML('<p>Hello There</p>',2);
$this->mpdf->Output(); 
}
?>
Step 4:
           That’s all you have done all steps. Click in export button to export to PDF and enjoy.

          This is how i generate PDF in PHP. Hope this post will help you a lot. Please do share and post your comments here. And If you have queries and if you want me to discuss then Please post your comments here. In my next post i will show you how to write your own helper file to generate PDF. So that you don't have to write much line of code, only you need to do is call helper and pass parameters to that. All the best. Have a good day.





What is the Difference between ASP and ASP.NET ?



My previous post was about "How to use memcache with PHP". Recently I received an request from my reader to write about "Key Differences Between Classic ASP And ASP.NET". In this article i will be discussing about differenciation of ASP and ASP.NET which is very useful for any technical interview, also for .NET beginners. I will sort out few key difference between ASP and ASP.NET as below.

ASP:

i. It has limited oops support and not having built in support for xml.

ii. Very less development and debugging tool available. Meaning that difficult to debug the code.

iii. ASP you can only do scripting using visual basic scripting and java scripting.

iv. Error handling is very poor.

v. It has no high level programming structure. Mixed of html and server side scripting.

vi. You must be entering first line as -


<%LANGUAGE="VBSCRIPT" CODEPAGE="960"%>

vii. It has no in built validation control. Meaning that validating page is difficult for developers.

viii. In the classic ASP if you need to update code on the existing page then it is mandatory to restart the server to get reflect.

ASP.NET

i. ASP.NET is full featured object oriented programming.

ii. It has full support of xml. Which helps easy data exchange.

iii. Various tools and compiler available. Microsoft Visual studio makes your debugging job easier.

iv. ASP.NET we can use either C# or VB.NET as server side programming language.

v. ASP.NET gives you three tire architecture. It allow you to keep your business logic, views everything separate. Meaning that easy to enhance applications.

vi. Error handling is very good.

vii. You are required to make language directive with page as below.


<%@Page Language="VB" CodePage="960"%> 
<%@QutputCache Duration="60" VaryByParam="none" %> 

viii. It has state management support.

ix. In built validation controls. It has rich validation set - custom validator, range validator, regular expression, compare and require field validation control which makes your job easier.

These are the major differences between classic ASP and ASP.NET. If this helpful to you then please don't forget to like, share with friends or comment below.

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2015 appsntech.com. All rights reserved. Powered By- Sanjoy Dey Productions