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);
  }

Thursday, September 13, 2018

How to read gmail email integration using imap php [Solved]

Hey Every once after a lot of R&D from google, now we could configure the email content read successfully here is the example of how to retrieve the email content.

PHP script email reader.php

here is the complete PHP script 
<?php 
set_time_limit(3000); 
   /* connect to gmail with your credentials */
   $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
   $username = 'Bikash@bikash.com'; 
   $password = 'XXXXX#';
   /* try to connect */
   $inbox = imap_open($hostname,$username,$password);
   /* get all new emails. If set to 'ALL' instead 
    * of 'NEW' retrieves all the emails, but can be 
    * resource intensive, so the following variable, 
    * $max_emails, puts the limit on the number of emails downloaded. 
    */
   //$emails = imap_search($inbox,'ALL');
    $date = date ( "d M Y", strToTime ( "-1 days" ) );
             $emails = imap_search($inbox,'FROM "no-reply@tableau.com" SINCE "'.$date.'"');
   /* useful only if the above search is set to 'ALL' */
   $max_emails = 5;
   /* if any emails found, iterate through each email */
   if($emails) {
                                $count = 1;
    /* put the newest emails on top */
    rsort($emails);
    /* for every email... */
    $ArrayMessage = array();
    foreach($emails as $email_number) {
     //get information specific to this email
     $overviewData = imap_fetch_overview($inbox,$email_number,0);
     //echo '<pre>'; print_r($overviewData);
     if(count($overviewData>0)){
                         $object                      = new stdClass();
    $object->msgno               = trim($overviewData[0]->msgno);
    $object->uid                 = trim($overviewData[0]->uid);
    $object->from                = trim($overviewData[0]->from);
    $object->to                  = trim($overviewData[0]->to);
    $object->subject             = $overviewData[0]->subject;
    $object->message_id          = $overviewData[0]->message_id;
    $object->size                = $overviewData[0]->size;
    $object->recent              = $overviewData[0]->recent;
    $object->flagged             = $overviewData[0]->flagged;
    $object->answered            = $overviewData[0]->answered;
    $object->deleted             = $overviewData[0]->deleted;
    $object->seen                = $overviewData[0]->seen;
    $object->draft               = $overviewData[0]->draft;
    $object->udate               = $overviewData[0]->udate;
//do store your database as per required
}}}
//Hope it will help you!
?>