Tuesday, October 9, 2018

How to download static docx file using php[Solved]

hey Guys, After lot of R&D I found the solution to download docx file using PHP.
Below is the example code.
function downloadDocx(){
$file = 'bikash_university.docx'
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
echo "<h1>Content error</h1><p>The file does not exist!</p>";
}

Friday, September 21, 2018

How to check whether email is read by user using PHP[SOLVED]

Below is the complete code using in php for sending email and read the status if use has opened the mail or not
call the function 
function sendEamil(201, 'bikash ranjan', 'harihar@gmail.com','Harihar','Nayak');
Declared below function to send the email
function sendEamil($id='', $to_name='', $to_address='',$firstName,$lastName){
    $from_name     = 'Bikash ranjan nayak';
    $from_address  = 'nayak.bikash@gmail.com';
    $reply_address  = 'no-reply@gmail.com';    
    $bccEmail    = 'nayak.bikash@yahoo.com';
    $contact_name  = $firstName." ".$lastName;   
    //set hidden url for captured the read mail
    $hiddenUrl      = 'http:127.0.0.1/readmail/readmail.php?type=table&id='.$id;
    
   $maildescription ='<!doctype html>
 <html>
 <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>php technical group</title>
   
 </head>';
  $contentBOdy.= 'Body HTML contents';  
  
  $maildescription.= '<body bgcolor="#ffffff" width="100%" style="margin: 0;" yahoo="yahoo">
    '.$contentBOdy.'
   
    <div style="display:none">
        <img alt="" src="'.$hiddenUrl.'" width="0px" height="0px" />
    </div>
</body>

</html>';
    
// Mail Description ( HTML ) End here
    // Mail Header
    $subject  = "Register form";
    $mime_boundary = "----PHP technical Register form ----".MD5(TIME().$id.TIME());
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Date:".date('r', $_SERVER['REQUEST_TIME'])."\n";
    $headers .= "Message-ID:<" . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) .$id. "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "From:".$from_name."<".$from_address.">\n";
    $headers .= "Bcc:".$bccEmail." \n";
    $headers .= "Reply-To:".$from_name."<".$reply_address.">\n";
    $headers .= "Return-Path:".$from_name."<".$reply_address.">\n";
    $headers .= "X-Mailer: PHP v".phpversion()."\n";
    $headers .= "X-Originating-IP:".$_SERVER['SERVER_ADDR']."\n";
    $headers .= "X-MessageID:".$id."\n";
    $headers .= "X-ListMember:".$to_address."\n";
    $headers .= "Precedence: bulk\n";
    $headers .= "Bounces-To: ".$reply_address."\n";
    $headers .= "List-Unsubscribe: <https://phptechnicalgroups.blogspot.com>\n";
    $headers .= "List-Owner: <mailto:".$from_address.">\n";
    $headers .= "X-Feedback-ID:"."2016:".$id.":event:register\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$mime_boundary\"\n";
    $setReturnPath = "<webmaster@phptechncalgrop.com>";
    $additional = "-f".$setReturnPath;

    //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";
    $message .= "Content-Transfer-Encoding: base64\n";
    $mailsent = mail($to_address, $subject, $message, $headers,$additional);
    return ($mailsent)?(true):(false);
  }