Showing posts with label Zend Framework. Show all posts
Showing posts with label Zend Framework. Show all posts

Saturday 2 May 2015

How to set authorization header in Curl using zend framework

 How to set authorization header in Curl using zend framework

 How to set authorization header in Curl using Zend Framework
   $url ='www.domain.com/web-service-API';
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    
    $client = new Zend_Http_Client($url, $config);
    //Set the Header value
    $client->setAuth('username', 'password!');
    
    $response = $client->request('GET'); 
    echo $response->getBody();



Set header (Name & Value) in curl using Zend Framework
$url ='www.domain.com/web-service-API';
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    
    $client = new Zend_Http_Client($url, $config);
    //Set the Header value
    $client->setHeaders('HEADER-NAME', 'Header-Value');
    
    $response = $client->request('GET'); //Here you can set GET Method Also
    echo $response->getBody();   



Send the JSON Data in curl using Zend Framework
$url ='www.domain.com/web-service-API';
$json = json_encode(array('name'=>'Web','age'=>20));
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    $response = $client->setRawData($json, 'application/json')->request('POST');
    echo $response->getBody();




Question: How to Set the username/password in CURL?
curl -X POST -u "USERNAME":"PASSWORD" --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked"  "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize" 




Question: How to pass binary User Authentication (Username/password) in CURL ?
$file='http://example.com/test/GM-qE2zq-1078-5525_360p.flac';
$jsonData = '';        
$config = array(
       'adapter' => 'Zend_Http_Client_Adapter_Curl',
       'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
   );
    $url='https://stream.watsonplatform.net/speech-to-text/api/v1/recognize';
   $client = new Zend_Http_Client($url, $config);
   //Set the Header value
        $client->setHeaders('Content-Type', 'audio/flac');
    $client->setHeaders('Transfer-Encoding', 'chunked');            

   $client->setRawData(file_get_contents($file));
    //Set post method    
   $response = $client->request('POST'); 
   $jsonData= ($response->getBody());

Thursday 30 April 2015

How to delete the Zend Cache files from server


How to delete the zend cache files from server


How to create an object of Zend Cache
$cache = Zend_Cache::factory(
                        'Core', 'File', array(
                    'lifetime' => 3600 * 24 * 7, //cache is cleaned once a day                            
                    'automatic_serialization' => true
                        ), array('cache_dir' => APPLICATION_PATH . '/cache')
        );


Remove the cache by cache-id In this only one cache file will be removed from server.
$cache->remove('idToRemove');


Remove All cache files from Server. (When we delete files, caching automatic clear because we are using cache in files)
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);


Remove all outdated caching files.
$cache->clean(Zend_Cache::CLEANING_MODE_OLD);


Remove the cahe files which have two tags.
$cache->clean(
    Zend_Cache::CLEANING_MODE_MATCHING_TAG,
    array('matchingTag1', 'matchingTag2','matchingTag3') //Will remove which have matchingTag1 and matchingTag2 and matchingTag3
);


Remove all files which have not tag assign few tags.
$cache->clean(
    Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
    array('NotmatchingTag1', 'NotmatchingTag2') //Will Remove all the cahce which are NOT tagged with NotmatchingTag1 OR NotmatchingTag2
);


Remove all the cache files which have any tag (any of two or three).
$cache->clean(
    Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, //Will remove which have matchingTag1 OR matchingTag2 OR matchingTag3
     array('matchingTag1', 'matchingTag2','matchingTag3')
);








Monday 16 March 2015

How to send an email using Email Template in Zend Framework

How to send an email using Email Template in Zend Framework

Email functionalities in websites is very common and used in mostly in all web application. Whether it is registration process or Order detail, we need to send an email to your valuable client.

To send the email using Email Template follow the following steps
1. First collect all the data which you want to send in Email like first name, last name etc.
$emailTemplateData = array('fname'=>'Web Technology','lname'=>'Experts Notes');


2. Create a Folder with name emails, where you can put the email templates files.
Email template Location: application/views/scripts/emails


3. Create a template with name registration.phtml  for registration Email and add following contents.
First name:  echo $data['fname'];  
Last name:   echo $data['fname'];  
Folder Location: application/views/scripts/emails
Don't forget to add php scripts for php variable
Im just giving you an working code, you can add lot of variables as you need.


Add following code from where you want to send an email
$subject ='This is subject';
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . '/views/scripts/emails');
$view->data = $emailTemplateData; //$emailTemplateData must have the values which you are using in registration.phtml
$emailHtml = $view->render('registration.phtml');
$mail = new Zend_Mail();
$mail->setBodyHtml($emailHtml);
$mail->setSubject($subject);              
$mail->setFrom("support@example.com", "From domain.com");
$mail->send();


If you get an issue regarding this post, Please comment below. we will try to fix your problem.




Monday 2 March 2015

Get Youtube video-details and comments using PHP

Get Youtube video-details and comments using PHP

How to get youtube video detail in Zend (Response in JSON)
$uTubeVideoCode ='ryJReIcMGOs';        
        $jsonData='';
        try{            
            $client = new Zend_Http_Client("http://gdata.youtube.com/feeds/api/videos/{$uTubeVideoCode}?v=2&alt=json");
            $response = $client->request('GET');
            $jsonData = $response->getBody();
        
        }  catch (Exception $e){
            echo "Error:".$e->getMessage();
            
        }    
        echo $jsonData;die;

Output:
{"version":"1.0","encoding":"UTF-8","entry":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$yt":"http://gdata.youtube.com/schemas/2007","xmlns$media":"http://search.yahoo.com/mrss/","gd$etag":"W/\"CkACQn47eCp7I2A9XRRWEkU.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs"},"published":{"$t":"2015-02-22T05:17:46.000Z"},"updated":{"$t":"2015-03-02T07:19:23.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#video"},{"scheme":"http://gdata.youtube.com/schemas/2007/categories.cat","term":"People","label":"People & Blogs"}],"title":{"$t":"ICC Cricket World Cup 2015 India Vs South Africa Game 13 Highlights - IND VS SA 22/02/15 2015"},"content":{"type":"application/x-shockwave-flash","src":"http://www.youtube.com/v/ryJReIcMGOs?version=3&f=videos&app=youtube_gdata"},"link":[{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs&feature=youtube_gdata"},{"rel":"http://gdata.youtube.com/schemas/2007#video.related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/related?v=2"},{"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html","href":"http://m.youtube.com/details?v=ryJReIcMGOs"},{"rel":"http://gdata.youtube.com/schemas/2007#uploader","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/users/ZBJOTQ3A-HYLRmpYm4hDeA?v=2"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"}],"author":[{"name":{"$t":"SGZ Cricket"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/SGZCricket"},"yt$userId":{"$t":"ZBJOTQ3A-HYLRmpYm4hDeA"}}],"yt$accessControl":[{"action":"comment","permission":"allowed"},{"action":"commentVote","permission":"allowed"},{"action":"videoRespond","permission":"moderated"},{"action":"rate","permission":"allowed"},{"action":"embed","permission":"allowed"},{"action":"list","permission":"allowed"},{"action":"autoPlay","permission":"allowed"},{"action":"syndicate","permission":"allowed"}],"gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments?v=2","countHint":32}},"yt$hd":{},"media$group":{"media$category":[{"$t":"People","label":"People & Blogs","scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],"media$content":[{"url":"http://www.youtube.com/v/ryJReIcMGOs?version=3&f=videos&app=youtube_gdata","type":"application/x-shockwave-flash","medium":"video","isDefault":"true","expression":"full","duration":1544,"yt$format":5},{"url":"rtsp://r4---sn-a5m7zu7s.c.youtube.com/CiILENy73wIaGQnrGAyHeFEirxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp","type":"video/3gpp","medium":"video","expression":"full","duration":1544,"yt$format":1},{"url":"rtsp://r4---sn-a5m7zu7s.c.youtube.com/CiILENy73wIaGQnrGAyHeFEirxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp","type":"video/3gpp","medium":"video","expression":"full","duration":1544,"yt$format":6}],"media$credit":[{"$t":"sgzcricket","role":"uploader","scheme":"urn:youtube","yt$display":"SGZ Cricket","yt$type":"partner"}],"media$description":{"$t":"ICC Cricket World Cup 2015 India Vs South Africa Game 13 Highlights - IND VS SA 22/02/15 2015\n\nICC Cricket World Cup 2015 India Vs Pakistan Game 4 Highlights - IND VS PAK 15/2/15\n\nICC Cricket World Cup 2015 India Vs South Africa\nICC Cricket World Cup 2015 India Vs South Africa 2/22/15\nICC Cricket World Cup 2015 India Vs South Africa 22 February 2015\n\nSubscribe For More Videos : https://www.youtube.com/user/SGZCricket\nGoogle + : https://plus.google.com/u/0/b/1093080...\n\nExtra Tag : ICC Cricket World Cup 2015 India Vs South Africa 2/22/15 ICC Cricket World Cup 2015 India Vs South Africa 2/22/15 2015 ICC Cricket World Cup 2015 India Vs South Africa 2/22/15 Full Match ICC Cricket World Cup 2015 India Vs South Africa 2/22/15 Highlights ICC Cricket World Cup 2015 India Vs South Africa 02/22/15 Full Results","type":"plain"},"media$keywords":{},"media$license":{"$t":"youtube","type":"text/html","href":"http://www.youtube.com/t/terms"},"media$player":{"url":"http://www.youtube.com/watch?v=ryJReIcMGOs&feature=youtube_gdata_player"},"media$thumbnail":[{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/default.jpg","height":90,"width":120,"time":"00:12:52","yt$name":"default"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/mqdefault.jpg","height":180,"width":320,"yt$name":"mqdefault"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/hqdefault.jpg","height":360,"width":480,"yt$name":"hqdefault"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/sddefault.jpg","height":480,"width":640,"yt$name":"sddefault"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/1.jpg","height":90,"width":120,"time":"00:06:26","yt$name":"start"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/2.jpg","height":90,"width":120,"time":"00:12:52","yt$name":"middle"},{"url":"http://i.ytimg.com/vi/ryJReIcMGOs/3.jpg","height":90,"width":120,"time":"00:19:18","yt$name":"end"}],"media$title":{"$t":"ICC Cricket World Cup 2015 India Vs South Africa Game 13 Highlights - IND VS SA 22/02/15 2015","type":"plain"},"yt$aspectRatio":{"$t":"widescreen"},"yt$duration":{"seconds":"1544"},"yt$uploaded":{"$t":"2015-02-22T05:17:46.000Z"},"yt$uploaderId":{"$t":"UCZBJOTQ3A-HYLRmpYm4hDeA"},"yt$videoid":{"$t":"ryJReIcMGOs"}},"gd$rating":{"average":1.6350245,"max":5,"min":1,"numRaters":1222,"rel":"http://schemas.google.com/g/2005#overall"},"yt$statistics":{"favoriteCount":"0","viewCount":"397572"},"yt$rating":{"numDislikes":"1028","numLikes":"194"}}}


How to get youtube video comments in Zend(Response in JSON)
        $uTubeVideoCode ='ryJReIcMGOs';        
        $jsonData='';
        try{            
            $client = new Zend_Http_Client("http://gdata.youtube.com/feeds/api/videos/{$uTubeVideoCode}/comments?v=2&alt=json");
            $response = $client->request('GET');
            $jsonData = $response->getBody();
        
        }  catch (Exception $e){
            echo "Error:".$e->getMessage();
            
        } 
echo $jsonData;  

Output:

{"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$openSearch":"http://a9.com/-/spec/opensearch/1.1/","xmlns$yt":"http://gdata.youtube.com/schemas/2007","gd$etag":"W/\"CUYAQ3kzfCp7I2A9XRRWEkU.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comments"},"updated":{"$t":"2015-03-02T07:59:02.784Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"logo":{"$t":"http://www.gstatic.com/youtube/img/logo.png"},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments?v=2"},{"rel":"http://schemas.google.com/g/2005#batch","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/batch?v=2"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments?alt=json&max-results=25&v=2"},{"rel":"service","type":"application/atomsvc+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments?alt=atom-service&v=2"}],"author":[{"name":{"$t":"YouTube"},"uri":{"$t":"http://www.youtube.com/"}}],"generator":{"$t":"YouTube data API","version":"2.1","uri":"http://gdata.youtube.com"},"openSearch$totalResults":{"$t":21},"openSearch$itemsPerPage":{"$t":25},"entry":[{"gd$etag":"W/\"AkQDRX47eCp7I2A9XRRXFk0.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13yynd4ssvaubg4n04cf3sytyaijddqwkc0k"},"published":{"$t":"2015-02-22T12:32:54.000Z"},"updated":{"$t":"2015-02-22T12:32:54.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"woooooooooooooooow\ufeff"},"content":{"$t":"woooooooooooooooow\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13yynd4ssvaubg4n04cf3sytyaijddqwkc0k?v=2"}],"author":[{"name":{"$t":"Rujul Deshpande"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/lIx3u1pJAyoxSMT2YAoEjg"},"yt$userId":{"$t":"lIx3u1pJAyoxSMT2YAoEjg"}}],"yt$channelId":{"$t":"UClIx3u1pJAyoxSMT2YAoEjg"},"yt$googlePlusUserId":{"$t":"102896019321279244010"},"yt$replyCount":{"$t":1},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"C04NRH47eCp7I2A9XRRXFko.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12oh5xbdqmmtdgii04ce33x5xz1xz3yrag"},"published":{"$t":"2015-02-23T06:13:15.000Z"},"updated":{"$t":"2015-02-23T06:13:15.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"can someone tell me ..."},"content":{"$t":"can someone tell me which game is this???\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12oh5xbdqmmtdgii04ce33x5xz1xz3yrag?v=2"}],"author":[{"name":{"$t":"sajan sebastian"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/xzNmG-CxBF8AkMEtmtaCOw"},"yt$userId":{"$t":"xzNmG-CxBF8AkMEtmtaCOw"}}],"yt$channelId":{"$t":"UCxzNmG-CxBF8AkMEtmtaCOw"},"yt$googlePlusUserId":{"$t":"116346366931114012924"},"yt$replyCount":{"$t":1},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"D0IDQn47eCp7I2A9XRRXF0s.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13hexfyzsigv5fd322qez1xupbbyvnee"},"published":{"$t":"2015-02-24T08:12:53.000Z"},"updated":{"$t":"2015-02-24T08:12:53.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"SGZ cricket..... ..."},"content":{"$t":"SGZ cricket..... grow up...\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13hexfyzsigv5fd322qez1xupbbyvnee?v=2"}],"author":[{"name":{"$t":"Roshan More"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/mZCY2FMCPkNn8RdNlPf0ww"},"yt$userId":{"$t":"mZCY2FMCPkNn8RdNlPf0ww"}}],"yt$channelId":{"$t":"UCmZCY2FMCPkNn8RdNlPf0ww"},"yt$googlePlusUserId":{"$t":"101759163693693799937"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"AkYFQX47eCp7I2A9XRRWEE8.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12yf5libtipzjki104cenrhvobhyftj2lk0k"},"published":{"$t":"2015-02-27T09:08:30.000Z"},"updated":{"$t":"2015-02-27T09:08:30.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"In this World cup ..."},"content":{"$t":"In this World cup each and every matches are interesting but only match \nschesule is not perfect ....\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12yf5libtipzjki104cenrhvobhyftj2lk0k?v=2"}],"author":[{"name":{"$t":"Nikunj Goletar"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/Shu6BVmlTRMgS_HtaB9yzQ"},"yt$userId":{"$t":"Shu6BVmlTRMgS_HtaB9yzQ"}}],"yt$channelId":{"$t":"UCShu6BVmlTRMgS_HtaB9yzQ"},"yt$googlePlusUserId":{"$t":"108529240828297091468"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"DUYGQX47eCp7I2A9XRRXFk0.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13juluxpmepddgrr04cjb2gnvvfhndyzp00k"},"published":{"$t":"2015-02-22T12:12:00.000Z"},"updated":{"$t":"2015-02-22T12:12:00.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"may i know the name ..."},"content":{"$t":"may i know the name of the game\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13juluxpmepddgrr04cjb2gnvvfhndyzp00k?v=2"}],"author":[{"name":{"$t":"Gopinath V"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/tamilanxxx"},"yt$userId":{"$t":"9Qu8ceBfkJ9txoCO3k3ENw"}}],"yt$channelId":{"$t":"UC9Qu8ceBfkJ9txoCO3k3ENw"},"yt$googlePlusUserId":{"$t":"115360643619137243306"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"CUMBRH47eCp7I2A9XRRWEE4.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13oyzgwvlroujxzu04cjjryjpyzwnmil54"},"published":{"$t":"2015-02-27T10:37:35.000Z"},"updated":{"$t":"2015-02-27T10:37:35.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"woooooooooooooooow\ufeff"},"content":{"$t":"woooooooooooooooow\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13oyzgwvlroujxzu04cjjryjpyzwnmil54?v=2"}],"author":[{"name":{"$t":"Husnain shah"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/__NO_YOUTUBE_ACCOUNT__"},"yt$userId":{"$t":"__NO_YOUTUBE_ACCOUNT__"}}],"yt$channelId":{"$t":"UC__NO_YOUTUBE_ACCOUNT__"},"yt$googlePlusUserId":{"$t":"113607893143655172508"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"C0MDSX47eCp7I2A9XRRWEko.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13mfpo41z3jebh2v22ggr5xtuqvyn2eo"},"published":{"$t":"2015-03-02T04:44:38.000Z"},"updated":{"$t":"2015-03-02T04:44:38.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"congrates\ufeff"},"content":{"$t":"congrates\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13mfpo41z3jebh2v22ggr5xtuqvyn2eo?v=2"}],"author":[{"name":{"$t":"Amol Awasthi"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/THBPSc-ik_m440Djkhe0ew"},"yt$userId":{"$t":"THBPSc-ik_m440Djkhe0ew"}}],"yt$channelId":{"$t":"UCTHBPSc-ik_m440Djkhe0ew"},"yt$googlePlusUserId":{"$t":"118383318670254507980"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"DUMERn47eCp7I2A9XRRWEE8.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13bs11qzp2kjvpsj22ecvjb5ouvh1ilb"},"published":{"$t":"2015-02-27T08:56:47.000Z"},"updated":{"$t":"2015-02-27T08:56:47.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"haha you are the ..."},"content":{"$t":"haha you are the world fellow ever\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13bs11qzp2kjvpsj22ecvjb5ouvh1ilb?v=2"}],"author":[{"name":{"$t":"nani98663"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/nani98663"},"yt$userId":{"$t":"_oMue9jTfGX75AQUxeceiw"}}],"yt$channelId":{"$t":"UC_oMue9jTfGX75AQUxeceiw"},"yt$googlePlusUserId":{"$t":"115292334965355156920"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"DkYMQX47eCp7I2A9XRRXGEQ.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12th1ditzvedbxsp22kxxlzeuucfbrcw"},"published":{"$t":"2015-02-25T19:56:20.000Z"},"updated":{"$t":"2015-02-25T19:56:20.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"seriously grow up ..."},"content":{"$t":"seriously grow up man\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12th1ditzvedbxsp22kxxlzeuucfbrcw?v=2"}],"author":[{"name":{"$t":"Ishan Shinde"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/5nefuBa-wS5dlh9mthIsQQ"},"yt$userId":{"$t":"5nefuBa-wS5dlh9mthIsQQ"}}],"yt$channelId":{"$t":"UC5nefuBa-wS5dlh9mthIsQQ"},"yt$googlePlusUserId":{"$t":"115372824146721655757"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"A0YNSX47eCp7I2A9XRRXF00.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13pgp5yirr0wtxik04civwpimrcerapvek"},"published":{"$t":"2015-02-23T16:33:18.000Z"},"updated":{"$t":"2015-02-23T16:33:18.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"hell no.... how ..."},"content":{"$t":"hell no.... how interesting....lol\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13pgp5yirr0wtxik04civwpimrcerapvek?v=2"}],"author":[{"name":{"$t":"Darshan Jain"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/TmQQ8VHwustduwHXiLowWg"},"yt$userId":{"$t":"TmQQ8VHwustduwHXiLowWg"}}],"yt$channelId":{"$t":"UCTmQQ8VHwustduwHXiLowWg"},"yt$googlePlusUserId":{"$t":"116504884552174068967"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"DEMER347eCp7I2A9XRRXGEQ.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13utrm4zyjgwd20n22tfnzqzvuehh5lc"},"published":{"$t":"2015-02-25T20:33:26.000Z"},"updated":{"$t":"2015-02-25T20:33:26.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"Grow up friend\ufeff"},"content":{"$t":"Grow up friend\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13utrm4zyjgwd20n22tfnzqzvuehh5lc?v=2"}],"author":[{"name":{"$t":"abhijit kulkarni"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/abhijit0727"},"yt$userId":{"$t":"NWvmyhNFs1B8ljeaQXES1A"}}],"yt$channelId":{"$t":"UCNWvmyhNFs1B8ljeaQXES1A"},"yt$googlePlusUserId":{"$t":"105890333904958496583"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"D04DQ347eCp7I2A9XRRXF08.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12wxpvrlofxc5s0w23ownp4doe4wrx4r04"},"published":{"$t":"2015-02-23T21:12:52.000Z"},"updated":{"$t":"2015-02-23T21:12:52.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"wow the crowd sucks ..."},"content":{"$t":"wow the crowd sucks in this game\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12wxpvrlofxc5s0w23ownp4doe4wrx4r04?v=2"}],"author":[{"name":{"$t":"Mehul Shukla"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/mehulshukla04"},"yt$userId":{"$t":"xu8mQo6LHTGfYAG-j7mNug"}}],"yt$channelId":{"$t":"UCxu8mQo6LHTGfYAG-j7mNug"},"yt$googlePlusUserId":{"$t":"105925848190989770553"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"A08BQ347eCp7I2A9XRRXF0g.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12wf3irhvr5sbbjq04ccx4rtz24yveq25k"},"published":{"$t":"2015-02-24T06:37:32.000Z"},"updated":{"$t":"2015-02-24T06:37:32.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"can u tell the name ..."},"content":{"$t":"can u tell the name of the game plss??????\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12wf3irhvr5sbbjq04ccx4rtz24yveq25k?v=2"}],"author":[{"name":{"$t":"nikhil kulal"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/HZacepyCMUAS5AzaKPImwA"},"yt$userId":{"$t":"HZacepyCMUAS5AzaKPImwA"}}],"yt$channelId":{"$t":"UCHZacepyCMUAS5AzaKPImwA"},"yt$googlePlusUserId":{"$t":"103284323473829074041"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"D04FRX47eCp7I2A9XRRXFkQ.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z125irwomybbexbvj23dwxqgbtbdyf0nc"},"published":{"$t":"2015-02-23T12:51:54.000Z"},"updated":{"$t":"2015-02-23T12:51:54.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"woow vata game\ufeff"},"content":{"$t":"woow vata game\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z125irwomybbexbvj23dwxqgbtbdyf0nc?v=2"}],"author":[{"name":{"$t":"pradeep appu"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/7j-ZZrFk6CylNMihVsV1vQ"},"yt$userId":{"$t":"7j-ZZrFk6CylNMihVsV1vQ"}}],"yt$channelId":{"$t":"UC7j-ZZrFk6CylNMihVsV1vQ"},"yt$googlePlusUserId":{"$t":"116605829416262485807"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"AkUNQn47eCp7I2A9XRRWEEo.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z121c51wuquciznns230yxnorkb2x34ai04"},"published":{"$t":"2015-02-27T23:04:53.000Z"},"updated":{"$t":"2015-02-27T23:04:53.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"superhero..indian . ..."},"content":{"$t":"superhero..indian ..jai ho\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z121c51wuquciznns230yxnorkb2x34ai04?v=2"}],"author":[{"name":{"$t":"chupbhosari terabaap"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/80XYP3ohlonHxFjyJxMg9w"},"yt$userId":{"$t":"80XYP3ohlonHxFjyJxMg9w"}}],"yt$channelId":{"$t":"UC80XYP3ohlonHxFjyJxMg9w"},"yt$googlePlusUserId":{"$t":"107946096902915779887"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"AkEGR347eCp7I2A9XRRXFkQ.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z13scpvijxithh0lm23dxpa5vkzsw50a304"},"published":{"$t":"2015-02-23T13:37:06.000Z"},"updated":{"$t":"2015-02-23T13:37:06.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"good\ufeff"},"content":{"$t":"good\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z13scpvijxithh0lm23dxpa5vkzsw50a304?v=2"}],"author":[{"name":{"$t":"Maha Linagam"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/mali4991"},"yt$userId":{"$t":"4NyMEDI3PVTVEM9Fga-K5Q"}}],"yt$channelId":{"$t":"UC4NyMEDI3PVTVEM9Fga-K5Q"},"yt$googlePlusUserId":{"$t":"103431499595674948971"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"DUAFRH47eCp7I2A9XRRXF00.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12nxdegiqzecxljo04chvn4dkzmuvwgdr00k"},"published":{"$t":"2015-02-23T16:08:35.000Z"},"updated":{"$t":"2015-02-23T16:08:35.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"dafuq is this???\ufeff"},"content":{"$t":"dafuq is this???\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12nxdegiqzecxljo04chvn4dkzmuvwgdr00k?v=2"}],"author":[{"name":{"$t":"Katherine May"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/Vvt17yrrm4cwZT5HakoHFw"},"yt$userId":{"$t":"Vvt17yrrm4cwZT5HakoHFw"}}],"yt$channelId":{"$t":"UCVvt17yrrm4cwZT5HakoHFw"},"yt$googlePlusUserId":{"$t":"105114308315934876966"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"CkIDSH47eCp7I2A9XRRXGUg.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12detpbmozjc5dms23csd4rkyvgsvnok04"},"published":{"$t":"2015-02-26T11:36:19.000Z"},"updated":{"$t":"2015-02-26T11:36:19.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":""},"content":{"$t":""},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12detpbmozjc5dms23csd4rkyvgsvnok04?v=2"}],"author":[{"name":{"$t":"Ashokkumar T"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/3kFgr6i5Ugr7aIYEZvU-Iw"},"yt$userId":{"$t":"3kFgr6i5Ugr7aIYEZvU-Iw"}}],"yt$channelId":{"$t":"UC3kFgr6i5Ugr7aIYEZvU-Iw"},"yt$googlePlusUserId":{"$t":"101665337513199560569"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}},{"gd$etag":"W/\"C0ANQn47eCp7I2A9XRRWEUQ.\"","id":{"$t":"tag:youtube.com,2008:video:ryJReIcMGOs:comment:z12uy31y3weyelzop04cgnoyloukhpvrcrs0k"},"published":{"$t":"2015-03-01T06:36:33.000Z"},"updated":{"$t":"2015-03-01T06:36:33.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#comment"}],"title":{"$t":"New inspiring song ..."},"content":{"$t":"New inspiring song for team india to win the world cup\nhttps://www.youtube.com/watch?v=vxNf1m2SiY0\ufeff"},"link":[{"rel":"related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs?v=2"},{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=ryJReIcMGOs"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/ryJReIcMGOs/comments/z12uy31y3weyelzop04cgnoyloukhpvrcrs0k?v=2"}],"author":[{"name":{"$t":"Kumar K"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/X0WlKnTMzGDgVDZ4TmWujQ"},"yt$userId":{"$t":"X0WlKnTMzGDgVDZ4TmWujQ"}}],"yt$channelId":{"$t":"UCX0WlKnTMzGDgVDZ4TmWujQ"},"yt$googlePlusUserId":{"$t":"116638980038801195984"},"yt$replyCount":{"$t":0},"yt$videoid":{"$t":"ryJReIcMGOs"}}]}}


Best Related Posts are Following:
1. How to send Email in Zend Framework - HTML Email
2. Send Email from Gmail SMTP using Zend Framework
3. Google trends api php - How to get hot trends
4. Multiple column ordering in Zend Framework
5. Current time zone for a city- Free API
6. Zend Gdata Youtube API - Search Video - View Video Detail
7. Download Videos from Amazon S3 - PHP
8. How to set Cron in Zend Framework
9. Zend Cache Tutorial - Zend Framework 1.12
10. Zend Framework Interview Questions and Answers for Experienced

Thursday 19 February 2015

How to send Attachment in Email in zend framework1 - Send PDF File

How to send Attachment in Email in zend framework1 - Send PDF File

Sending an attachment in Email is very easy in zend framework. Attachmnet can be PDF file, image file, text and excel file etc. For Different type of attachment have different types of mime type. For example pdf mime type is "application/pdf" where gif image mime type is "image/gif".

In E-commerce website, when an order is placed by customer on the online website. Customer get the order detail in form of Order PDF File, So that he can keep offline record too.


Following code snippet is for How to attach a PDF file in Email using Zend Framework.
 
  /** Must fill Following detail * */
        $emailTo = 'receipts@no-spam.ws';
        $emailToName = 'receipts Name';
        /** Must fill Following detail * */
        $emailSubject = 'This is subject';
        $emailBody = 'This is HTML Email Body';
        $fromEmail = 'fromemail@no-spam.ws';
        try {
            $config = array(
                'ssl' => 'tls',
                'auth' => 'login',
                'username' => 'SMTP_USERNAME',
                'password' => 'SMTP_PASSWORD'
            );
            $transport = new Zend_Mail_Transport_Smtp('SMTP_HOST', $config);

            $mail = new Zend_Mail();
            $mail->setBodyHtml($emailBody);
            $mail->setFrom($fromEmail);
            $mail->addTo($emailTo, $emailToName);
            $mail->setSubject($emailSubject);
            
            /**PDF Add Attachment **/
            $attachment = new Zend_Mime_Part('path to pdf file');
            $attachment->type        = 'application/pdf';
            $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
            $attachment->encoding = Zend_Mime::ENCODING_BASE64;
            $attachment->filename    = 'order.pdf';
            $mail->addAttachment($attachment);
            /** Add Attachment **/            

            if ($mail->send($transport)) {
                echo 'Sent successfully';
            } else {
                echo 'unable to send email';
            }
        } catch (Exception $e) {
            echo $e->getMessage();
        }



Different Types of Attachment 



Monday 9 February 2015

How to send Email in Zend Framework - HTML Email

How to send Email in Zend Framework - HTML Email


In websites, We send email to our clients for Following:
- Registration Email
- Forget Password
- Change Password
- Notification Email
- Newsletter
- Order completed
- Order In transist
- Order deliver Successfully


Following code, Which can be used to send email in Zend-Framework (HTML EMAIL).
 
/** Must fill Following detail * */
        $emailTo = 'receipts@no-spam.ws';
        $emailToName = 'receipts Name';
        /** Must fill Following detail * */
        $emailSubject = 'This is subject';
        $emailBody = 'This is HTML Email Body';
        $fromEmail = 'fromemail@no-spam.ws';
        try {
            $config = array(
                'ssl' => 'tls',
                'auth' => 'login',
                'username' => 'SMTP_USERNAME',
                'password' => 'SMTP_PASSWORD'
            );
            $transport = new Zend_Mail_Transport_Smtp('SMTP_HOST', $config);

            $mail = new Zend_Mail();
            $mail->setBodyHtml($emailBody);
            $mail->setFrom($fromEmail);
            $mail->addTo($emailTo, $emailToName);
            $mail->setSubject($emailSubject);
            if ($mail->send($transport)) {
                echo 'Sent successfully';
            } else {
                echo 'unable to send email';
            }
        } catch (Exception $e) {
            echo $e->getMessage();
        }

Above code is For html email, You can use html tags like bold, italic, table etc for sending rich text email.


Monday 2 February 2015

Send Email from Gmail SMTP using Zend Framework

Send Email from Gmail SMTP using Zend Framework

In Website we need to send email on Registration, Forget , Order email to our Clients/Customer.
We want email should be deliver timely in inbox folder not in junk/spam folder.
For this we have to use SMTP Server.

GMAIL SMTP Server is free to use, if you have valid Gmail account.

Just the following code to send email from your Gmail Account.
/** Must fill Following detail * */
$yourGmailAccountUsername = 'youremail@gmail.com';
$yourGmailAccountPassword = '********';
$emailTo = 'arun.compute@gmail.com';
$emailToName = 'receiptsName';
/** Must fill Following detail * */

/** Optional Detail * */
$emailBody = 'This is body text';
$emailSubject = 'This is subject';
/** Optional Detail * */

try {
    $config = array('ssl' => 'tls',
        'auth' => 'login',
        'username' => $yourGmailAccountUsername,
        'password' => $yourGmailAccountPassword);

    $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);


    $mail = new Zend_Mail();

    $mail->setBodyHtml($emailBody);
    $mail->setFrom($yourGmailAccountUsername);
    $mail->addTo($emailTo, $emailToName);
    $mail->setSubject($emailSubject);
    if ($mail->send($transport)) {
        echo 'Sent successfully';
    } else {
        echo 'unable to send email';
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

If you get similar to following Error
Please log in via your web browser and then try again.
5.7.14 Please log in via your web browser and then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 fr13sm3613053pdb.81

If Yes,
whether you have "turned on 2-Step Verification" OR Google need Verification that you want to use your gmail as SMTP credential.
you can fix this in couple of minutes using below link:
https://support.google.com/mail/answer/78754

If any issue, please comment below in comment box:




Tuesday 27 January 2015

Google trends api php - How to get hot trends

Google trends api php - How to get hot trends


Google Trends is a public web facility of Google Inc., based on Google Search, that shows how often a particular search-term is entered relative to the total search-volume across various regions of the world, and in various languages. 
From: en.wikipedia.org/wiki/Google_Trends


Use following code to get the hot trends from google.
  
try {            
            $url='http://www.google.com/trends/hottrends/atom/hourly';                        
            $client = new Zend_Http_Client($url);
            $response = $client->request('GET');
            $jsonData = ($response->getBody());
            echo 'Google Trends';            
            preg_match_all('/(.*)<\/a>/', $jsonData, $trends);
            /** preg_match_all('/(.*)<\/a>/', $jsonData, $trends);**/
             foreach($trends[0] as $trend) {
                echo "{$trend}";
                }

        } catch (Exception $e) {
            echo 'Error' . $e->getMessage();
        }     

Tuesday 9 December 2014

Multiple column ordering in Zend Framework

Multiple column ordering in Zend Framework

There are different ways to multiple column ordering in Zend. Following are two different ways to do multiple column ordering in Zend Framework. you can use either First way OR Second way.

First Way
->order(array('first_name asc','last_name desc'));

Second Way
->order('first_name asc')->order('last_name desc')


In above code snippet, First It will sort by first_name in ascending order then sort by last_name in descending order. you can also add more than two column in ordering.


Multiple column ordering in MySQL
select * from users order by first_name asc, last_name desc
First It will sort by first_name in ascending order then sort by last_name in descending order.


Friday 14 November 2014

Current time zone for a city- Free API

Current time zone for a city- Free API

Get TimeZone & Local time from Latitude/Longitude



$localtime = 0;
$latitude = '40.71417';
$longitude = '-74.00639';
try {
    $client = new Zend_Http_Client('http://www.earthtools.org/timezone-1.1/' . $latitude . '/' . $longitude);
    $response = $client->request('GET');
    $xmlData = $response->getBody();
    if (!empty($xmlData)) {
        $xmlData = simplexml_load_string($xmlData);  
        print_r($xmlData);
    }

} catch (Exception $e) {
    echo 'Error' . $e->getMessage();
}

Output:

SimpleXMLElement Object
(
    [version] => 1.0
    [location] => SimpleXMLElement Object
        (
            [latitude] => 40.71417
            [longitude] => -74.00639
        )
    [offset] => -5
    [suffix] => R
    [localtime] => 13 Nov 2014 01:42:07
    [isotime] => 2014-11-13 01:42:07 -0500
    [utctime] => 2014-11-13 06:42:07
    [dst] => Unknown
)


Get Latitude/Longitude from address


http://maps.googleapis.com/maps/api/geocode/json?address=chandigarh&sensor=false

Output:
http://maps.googleapis.com/maps/api/geocode/json?address=chandigarh&sensor=false