Wednesday, February 21, 2018

How to resolve DMARC and DKIM pass in mailer header in php

Hey    , Guy

I am sharing my experienced which I faced lot of effort to resolve the DKIM and DMARC fail issue on email sent.

Finally I resolved the issue using changing the header below and validate the html tag in your email body.


Here is the result of pass by google and test mailer

SPF:PASS with IP 203.85.210.401 Learn more
DKIM:'PASS' with domain gmail.com Learn more
DMARC:'PASS' 

function sendNewsLetter($id='', $to_name='', $to_address=''){

    $from_name    = 'Phptechnicalgroups';
    $from_address = 'contact@phptechnicalgroups.com';
    $reply_address = 'no-reply@phptechnicalgroups.com';
//hiddenUrl variable call when user read the email to identify
 $hiddenUrl      = 'http://phptechnicalgroups.blogspot.in/captcha.php?type=mailer_socialhub_february_2018&id='.$id;

$maildescription ='<html>
<head>

</head>

<body style="margin: 0; padding: 0;">
    <div style="display: none;">
        <img alt="" src="'.$hiddenUrl.'" width="0px" height="0px">
    </div>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Phptechnicalgroup - Social Hub Updates - January 2018</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</body>
</html>';
       $subject  = "Email Subject";
    $mime_boundary = "----php technical group----".MD5(TIME().$id.TIME());
    $additional ='webmaster@phptechnicalgroups.blogspot.in';
    $messageid = $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) .$id. '@' . $_SERVER['SERVER_NAME'];
    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= 'Return-Path: Intel Network Builders <no-reply@phptechnicalgroups.blogspot.in>'."\r\n";
    $headers .= 'X-Mailer: PHP v'.phpversion()."\r\n";
    $headers .= 'Message-ID:<'.$messageid.'>'."\r\n";
    $headers .= 'X-Originating-IP:'.$_SERVER['SERVER_ADDR']."\r\n";
    $headers .= 'List-Unsubscribe: <mailto:contact@phptechnicalgroups.blogspot.in>'."\r\n";
    $headers .= 'From: php technical group <contact@phptechnicalgroups.blogspot.in>' . "\r\n";
    $headers .= 'Bcc:  <nayakr.bikash@gmail.com>' . "\r\n";
    $headers .= 'Reply-To: php technical group <no-reply@phptechnicalgroups.blogspot.in>' . "\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$mime_boundary\"\r\n";

//Create Email Body (HTML)
    $message = "--$mime_boundary\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= $maildescription;
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\n";
    
    $mailsent = mail($to_address, $subject, $message, $headers,'-f'.$additional);
    return ($mailsent)?(true):(false);
  }

Hopefully it will help you , thank you!

Friday, February 16, 2018

How to use loading image while downloading file like csv,xls ? [SOLVED]

Hey Guys,

Please follow the below step to download using ajax request in PHP and loader show while fetching and download the file .



//Total  members Registered in a month   
jQuery('#total-members-month-report').click(function(event){  
jQuery('.overlay').show();
var buildername = $('#builder-name').val();
var date1 = jQuery('#date1').val();
var date2 = jQuery('#date2').val();   
var URL = component_path+'&task=universityreport.registeredMembers&buildername='+buildername+'&date1='+date1+'&date2='+date2;
jQuery.ajax({url: URL, success: function(result){
        setTimeout(function(){ 
  window.location.href = URL;
  jQuery('.overlay').hide();
  }, 1000);
    }});
});

Hope it will help you!!

Thursday, February 8, 2018

How to create Dynamic div tag14 and 7 modular using php AJAX/JSON respone?


Hey Every once ,

I have made below function that create dynamic div for slider 14 and 7 modular which create for slider slick js 2*7 rows and in a slider box.

//create a function HTML OUT PUT
public function getCompleteHTMLOUTPUT($logoJsonDecode = array()){
$outputArray = array();
$assets  = JURI::base().'modules/mod_logo_slider/assets';
//echo "<pre>";
//print_r($logoJsonDecode);
//echo count($logoJsonDecode);
$totalLogoCount = count($logoJsonDecode);
$completeHTMLOUTPUT = '';
if(count($logoJsonDecode) > 0){
$completeHTMLOUTPUT = '<div class="slick-slide"><div>';
for($i=0,$count=1;$i<$totalLogoCount;$i++,$count++){
$logo = $logoJsonDecode[$i];
$blankDivFlag = false;
$wrapperDivFlag = false;
$url='';
if($logo->isMicroSite==0){
$url=$logo->company_url;
}else{
$url=JURI::ROOT().'ecosystem/'.$logo->microSiteURL;
}
$completeHTMLOUTPUT .='<div class="item" style="width: 14.2857%; display: inline-block;">';
$logoImage = str_replace('images/','',$logo->csp_logo_image);
$imagePath=JPATH_BUILDERS.'images/registeredcompanylogo/'.$logoImage;
list($width, $height) = getimagesize($imagePath);
$gaSource='Hits on External Links';
$rel = 'rel="nofollow"';
if($logo->isMicroSite==1)
{
$gaSource='Hits on Internal Links';
$rel = '';
}

$gafunc='onclick="ga(\'send\', \'event\', \''.$gaSource.'\', \''.$logo->organization_name.'\', \''.$url.'\');"';
$completeHTMLOUTPUT .='<a '. $rel.' title="'.$logo->organization_name.'" target="_blank" href="'.$url.'" '.$gafunc.'>
<img alt="'.$logo->organization_name.'" title="'.$logo->organization_name.'" data-lazy="'.JPATH_BUILDERS.'images/registeredcompanylogo/'.$logoImage.'" width="'.$width.'" height="'.$height.'" >
</a>
</div>';
if(($count % 14) == 0){
$completeHTMLOUTPUT .= '</div>';
$wrapperDivFlag = true;
$outputArray[] = $completeHTMLOUTPUT;
$completeHTMLOUTPUT = '';
if($i < $totalLogoCount){
$completeHTMLOUTPUT .= '<div class="slick-slide"><div>';
}
}else if(($count % 7) == 0){
$completeHTMLOUTPUT .= '</div>';
$blankDivFlag = true;
if($i < $totalLogoCount){
$completeHTMLOUTPUT .= '<div>';
}
}

}
if(!$blankDivFlag){
$completeHTMLOUTPUT .= '</div>';


}
if(!$wrapperDivFlag){
$completeHTMLOUTPUT .= '</div>';
}
$completeHTMLOUTPUT = '';
$outputArray[] = $completeHTMLOUTPUT;

}
return $outputArray;
exit;
}

// Call it passing JSON object to decode

$logoJsonDecode = json_decode($ajaxlogosList);

$completeHTMLOUTPUT = $this->getCompleteHTMLOUTPUT($logoJsonDecode);

Hope fully it will help you  for slider slick.

Friday, February 2, 2018

How to invoke large number of images in slick JS slider or dynamic in PHP?

Hey All,

I have made custom function of slick slider to load dynamically using AJAX process to append into  slider item automatically. its  large  number of records  processing in chunk split from your database base on counter in every request. good to know its loading within a second of initials page loading process.


Please follow the below step and do not copy fully code take the business logic from here and implement it your application.
--------------------------------------------------------------------------------------
Step1 : Create slider.php

<link rel="stylesheet" type="text/css" href="css/slick.css" />
<script type="text/javascript" src="js/slick.min.js"></script>

<div class="logo_list_ajax logo_display" id="logo_display" style="margin-top: 15px;">
<!-- Item  array contains logo and title from db-- total load 14 items for two row of slide>
<?php  foreach($items as $logo)  {?>

<div class="item">

<a title="<?php echo $logo->organization_name;?>" target="_blank" onclick="ga('send', 'event', '<?php echo $gaSource;?>', 'Links : <?php echo $logo->organization_name;?>', '<?php echo $url;?>');" href="<?php echo $url;?>">
<img alt="<?php echo $logo->organization_name;?>" title="<?php echo $logo->organization_name;?>" src="<?php echo JPATH_BUILDERS?>images/registeredcompanylogo/<?php echo $logoImage;?>" width='<?php echo $width;?>' height='<?php echo $height;?>' >
</a>

</div>
}?>
</div>

Step 2 : Create an ajax function that take the limit counter increment or  and get data list in JSON from server . it will automatically append to slider list 14item
---------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
var recurseStatus = false;
var html='';
var limitcounter=2;
var bbaseUrl='<?php echo JPATH_URL;?>';
var baseUrl='<?php echo JURI::ROOT();?>';
function logolist(){
var html='';
jQuery.ajax({
url : 'index.php?option=com_registration&task=ajaxItemList',
type: 'POST',
data:{'limitcounter':limitcounter}  ,               
success : function(respond){
limitcounter = limitcounter+1;
var objdata = jQuery.parseJSON(respond);
var data_length = objdata.length;
if(data_length>0){
var blankDivWrapper =jQuery('<div class="slick-slide"></div>');
var blankDiv =jQuery('<div></div>');
var blankDiveven =jQuery('<div></div>');
for (var i = 0,count=1; i < data_length; i++,count++) {
var imgLinkurl=gaSource=rel='';
if(objdata[i]['isMicroSite']==0){
gaSource='Hits on External Links';
rel = 'rel="nofollow"';
imgLinkurl=objdata[i]['company_url'];
}else{
imgLinkurl=baseUrl+'ecosystem/'+objdata[i]['microSiteURL'];
gaSource='Hits on Internal Links';
rel = '';
}
var getimageurl=objdata[i]['csp_logo_image'];
var replaceImage = getimageurl.replace("images/", "");

var gafunc='onclick="ga(\'send\', \'event\', \''+gaSource+'\', \''+objdata[i]['organization_name']+'\', \''+imgLinkurl+'\');"';
html+='<div class="item" style="width: 14.2857%; display: inline-block;">';
html+='<a '+gafunc+rel+' title="'+objdata[i]['organization_name']+'" target="_blank"  href="'+imgLinkurl+'">';
html+='<img id="img_'+objdata[i]['organization_id']+'" alt="'+objdata[i]['organization_name']+'" title="'+objdata[i]['organization_name']+'" src="'+builderbaseUrl+'images/registeredcompanylogo/'+replaceImage+'" ></a></div>';



}
if(recurseStatus){

logolist();
}
}

 
}
});

}
-------------------------------------------------------------------------------------------------------------------
//Call slider delegation of slick JS
jQuery(document).ready(function(){
jQuery(".logo_list_ajax").slick({
          autoplaySpeed:8e3,autoplay:!0,rows:2,
          slidesPerRow:7,fade:!0,infinite:!0,
           speed:1e3,onReInit:null,cssEase:"ease",
           pauseOnHover:!0});
//---------------------------------------------------------------------------------
// On before internalisation of slide change event slider
jQuery(".logo_list_ajax").on('beforeChange', function(event, slick, currentSlide, nextSlide){
if(!recurseStatus){
//one time call  function if even
  recurseStatus = true;
  logolist(true);
}
});
});
</script>
-------------------------------------------Ajax Server Function ajaxItemList-------------------------------------

public function ajaxItemList() {           
          try {
$limit = JRequest::getVar('limitcounter');
$offset=$limit*14;
                 $query="select * from item";
                $db->setQuery($query,$offset,14);
               $list_names = $db->loadAssocList();
            } catch (Exception $e) {
                 $list_names = array();
            }
             echo json_encode($list_names);
             exit;
            }

Finally , You have done large number records to you slider items, it would not taking the loading time to load page initially .

Hopefully it will help you, please comment if any question on this.