Jump to content

mark107

Members
  • Content Count

    94
  • Joined

  • Last visited

Posts posted by mark107

  1. 9 minutes ago, gw1500se said:

    Convert the date string to a time data type then compare:

    
    if(strtotime($test_date) < strtotime("now")) {
       $new_date=strtotime(&test_date. "+ 1 day");
    }
    // format $new_date however you need

    Thank you very much for this, but when I try this:

    if(strtotime($get_time) < strtotime("now")) {
       $autoresponder_date = strtotime($get_time. "+ 1 day");
    }
    
    echo $autoresponder_date;

     

    I am getting this:

    1575042480

     

    Any idea how i can convert it to date with the time?

  2. 3 minutes ago, gw1500se said:

    If I understand correctly, you need to see if the hour has gone past and if so increment the date.

    Yes this is what I am trying to do. I want to see if the hour has gone past and increment the date.

    How I can do that? Do I have to use something like this?

    if (date('H') > $get_time)
    {
         //let do something
    }

      

  3. Hi all,

    I am working on my PHP script to set up the date with the time for the autoresponder so I can send out the emails at the specific time. I need some help with set up the correct day date with the time, because on my code when I have two different times `06:00` and `20:00`, as both of them will show the time with the current day date, e.g: 28-11-2019. I find that my code have set up the date as incorrect because the time I have `06:00` which it should have set up with the next day date, e.g 29-11-2019 instead of 28-11-2019 and the time `20:00` should set up with the current day date as my current time is `15:26pm` right now. 


    Output for `$autoresponder_date`:

        2019-11-25 06:00
        2019-11-25 20:00


    Output for `$get_time`:

        06:00
        20:00


    Here is the code:

       

    $auto_responders = $link->prepare('SELECT * FROM autoresponder WHERE campaign = ? ORDER BY id ASC');
        $auto_responders->execute([$campaign]);
        $auto_responders->setFetchMode(PDO::FETCH_ASSOC);
        $auto_responders = $auto_responders->fetch(PDO::FETCH_ASSOC);
        $get_time = $auto_responders['send_time'];
        
        if ($get_time >= strtotime('00:00'))
        {
            $autoresponder_date = date('Y-m-d', strtotime($get_time . ' +1 day'));
        }
        else
        {
           $autoresponder_date = date('Y-m-d', strtotime($get_time));
        }
        $send_time = $autoresponder_date . ' '. date('H:i ', strtotime($get_time));

     

    Can you please show me an example how I can set up the day date for the time `06:00` and `20:00` as if I have the time is `06:00` then check if the time have passed before I could do anything to send the email and it is the same for the time `20:00:00`? 

    Thank you.

     

  4. Just now, Zane said:

    The more you reply with details the more it makes me understand that you're trying to extract the images from incoming HTML.  Am I correct on this?

    Yes.

    Can you also answer my questions regards to db that if it is a good idea to encode the HTML to store the hash in a db?

  5. 2 hours ago, maxxd said:

    Not to be a pedantic ass, but sometimes the data is client-created HTML content. Any CMS runs into this, and a lot of application-style sites I've worked on (including my current job) offer clients the option of customizing display text where it makes sense, and it can include lists and images and whatnot.

    Ok, I have come across to this post

    https://stackoverflow.com/questions/37338770/php-how-to-save-html-string-into-database

     

    It say that I can encode the HTML to store the hash in a database and when I get the hash I can decode them to go it back to where it was. Do you think if it is a good idea to do this to encode the HTML so I can store the hash in a database?

  6. 2 hours ago, ginerjm said:

    I have to ask - Why are you even DOING this thing with storing html in a db?  One stores DATA in a db.  Then one reads it and sends it to the client or processes it in a script and sends the results of that to the client.  Saving html code in a db is mind-boggling to me.  Never done it.  Probably never will.  As a beginner - why are you making this project so completely complicated by coming up with this idea??  Did you see a recommendation that told you to do it?

    No one have told me to do it. I have got emails that come with images in the HTML so I'm storing them in a db. I have got no idea how to store the DATA in a db when I'm fetching my emails using imap.

  7. 16 hours ago, Zane said:

    What you do is maintain a normalized database.  In other words, have a table for anything that you'd consider to be an important chunk of data.  For instance, attachments.  Ideally, you'd have an attachments table in your database.  Within this table, you want to put as much about each attachment as you can, as columns (table fields), with the ultimate goal being to have only one single unique row per attachment.  One attachment cannot be another.

    Here's a rundown of what I think you're looking at for a table schema.

    • id - you need a primary unique identifier for every attachment
    • email - Which email is this an attachment of?  You'd put an id in here that correlates to a specific email in another table called "emails".
    • image - Again, images are a good example of another good chunk of data.  So, put an id of an image from another table called "images".  This way you don't restrict images just to attachments.  Images lives matter too.  You could store everything about every image on your site in this table.  You can even give it a label to use for whatever reason you'd need a name for the image that isn't the filename.
    • filename - Obviously, this would just be a string containing the filename, and the filename only.  You might decide to change your URL structure one day, or reorganize folders, so just keep the filename.

    That's probably the most fundamental minimum schema you'd have.  Then, you have the emails and the images to store in their own separate tables.  Again, bare minimum:

    Emails Table

    • id - primary unique identifier for the email.
    • user_id - Assuming you have a user management system set up, I'm willing to bet there is a unique identifier for every user.  There's another table worth creating!
    • destination_address - What is the email address this message was sent to?
    • body - What is the message body of this email?
    • sent - Is this message sent?  Blink once for yes and zero times for no -- That's binary.
    • send_date - When was this message sent? Use a UNIX timestamp so you can output the date precisely as you want to.  Now, and in the future when you make decisions about change and stuff.

    For something like the "body" of an email, it's probably one of the few times it'd actually be logical to store HTML (that is encoded).  It's not likely you're going to change the way an email looks that has been sent.  For example, say you're on a mailing list for some site -- Site A.  If, for whatever reason, Site A decides to change their mailing list format that is sent out, you'd still be able to look at older emails from the mailing list and see what they've changed.

    Then, when all the proper SQL queries have been executed by a server side language, such as PHP, you can use that same language (PHP) to dynamically generate HTML.  Need a dropdown showing a list of all users?  Create a function that'll generate a <select> tag with <option> tags for each user.  Then, you just slap that sucker in whatever HTML you have set up and pretty it up with CSS.

    
    <div id="attachments">
    
         <div id="attachment_{$attachment_id}">
    
              <a href="{$attachment_filename}"><img src="somefolder/images/{$image_filename}" /></a>
    
         </div>
    
    </div>
    

    Where {$variable} is one of your PHP variables that contains the data you need.

    Look up Database Normalization on Google.  Get a feel for how data should be treated.  This is a decent article on it.

    Thank you for your advice. I have been modified on the code to add the attid, message-id and the filename so am I good to go?

    Here is what it look like:

    1562453336 attid: 0.1 msessage-id: 455a7a38554a364e577233426974544a4c49397359513d3d filename: noname.gif 1562453336 attid: 0.2 msessage-id: 455a7a38554a364e577233426974544a4c49397359513d3d filename: what-is-bootstrap.png --------------------------Image body
    
    1562023807 attid:0 msessage-id: 655337787a6b7957356e316468667431736d415944673d3d filename: chromegmailnew-vertical-allowed-1366.png 1562023807 attid:1 msessage-id: 655337787a6b7957356e316468667431736d415944673d3d filename: example.png --------------------------test attachment 11
    
    1562014561 attid:0 msessage-id: 706b337a314d6b30563352484d615461764a594461513d3d filename: example.png 1562014561 attid:1 msessage-id: 706b337a314d6b30563352484d615461764a594461513d3d filename: chromegmailnew-vertical-allowed-1366.png --------------------------Test attachments no 9
    
    1562013859 attid:0 msessage-id: 77634b38635a39596a6b56465a314e4d574531776b773d3d filename: chromegmailnew-vertical-allowed-1366.png 1562013859 attid:1 msessage-id: 77634b38635a39596a6b56465a314e4d574531776b773d3d filename: chromegmailnew-vertical-allowed-1366.png 1562013859 attid:2 msessage-id: 77634b38635a39596a6b56465a314e4d574531776b773d3d filename: example.png 1562013859 attid:3 msessage-id: 77634b38635a39596a6b56465a314e4d574531776b773d3d filename: example.png --------------------------Test attachments no 6

     

    I think it would be easier if I put them in the attachments column with attid, message-id and filename so I can find the filename I am looking for using attid following by id that I search through in a database. Please let me know if I am doing it correct so I will insert these data to be storing in a database.

    However, I have been told that it would not be a good idea to store the images and attachments in a database so I would need to use fwrite to store the data on my server.

    Here is the Email Table:

    • id - I use INIT to store my name and email address
    • uid - I use TEXT to store emails uid
    • from_email - I use TEXT to store the name and sender email address
    • to_email - I use TEXT to store my name and email address
    • subject - I use TEXT to store the subject
    • message - I use BLOB to store the messages in HTML
    • attachments - I use BLOB to store the attachments in HTML
    • header - I use BLOB to store the header as HTML
    • readtype - I use TEXT to store the text as read/unread
    • received_date - I use datetime to store the date and time when they sent the emails

     

    If you find anything wrong with my database or what changes I would need to make so please let me know.

    I have storing the email body as HTML in a database so am I good to go?

    As for the other file index.php, you can see in my code that I am using the variables to get the id, attid and messageid from the address bar. I guess that if I want to find the images to display, I would have to use `$_GET['id']` to get the id from the address bar to find it through in a database row for that email, then I would have to use `$_GET['attid']` to find the string for the attid in the attachments column to get the strings for the filename so I could link it to where the files are located on my server. Am I correct? 

  8. 2 minutes ago, requinix said:

    Because extracting the filename, and other information, from that HTML is really really painful. And who's to say you want that exact markup all the time? What if you need to change it to something different?

    The concept we're touching on here is separating data from presentation. Attachment IDs and filenames are data, DIVs and IMGs are presentation. The data comes from an email and had nothing to do with HTML, and HTML can quite happily exist without dealing with your attachments. They are two different things and need to be kept separate. What you do later is use HTML to show the attachments.

    Basically, yes. When you want that HTML on your page you output it at that moment - the same way you're already doing for everything else.

    I... don't know why this is a question. Surely you've written PHP code for a webpage? You know, HTML tags here, PHP tags there, assorted echo statements...

    ...What?

    Oh I see, I can see I have make a mistake so I will need to change the code again. I am just learning what I must do and what I must do as I am doing this for the first time never done this before.

    So when I store the message-id, attach-id and filename in a database, how  I can get the images to display in index.php when I click to open my emails?

  9. 10 minutes ago, requinix said:

    Okay, then your first problem is that you're storing the attachments as HTML in your database.

    Don't do that. You see how hard it is to work with those, right?

    Store the individual pieces of information about each attachment. The message ID, attachment ID, name, whatever.

    Yep, I am storing the attachments as HTML in a database. Why I don't do that?

    Do I have to remove the HTML tags and store the filenames, message-id, attach-id in a database just like this?

    Quote

     

    message-id: 4124 - attach-id: 5768 filename: what-is-bootstrap.png

    message-id: 9041 - attach-id: 1690 filename: noname.gif

     


    How I can make the html tags?

    Do I have to make the html tags when I click on my emails to fetch the message-id, attach-id and filename from the database to make the html tags to put them on my page?
     

  10. 1 hour ago, Zane said:

    I don't understand from your code: Which part contains the image tag?  Or, do you just have a column for filenames or something and want to create a relative URL for it?

    What you mean by which part contains the image tag? i am only using the image tag like <img where you can see in the attached pics.

    No I dont have a column for filenames but I have a column called attachments that I have stored the html tags in a database with the filename like this:

    <a id='download_attachment' role='link' class='aQy e' href='http://example.com/project433q325/u/?id=71664b6a654a6176434c346c773348337054733779413d3d&attid=0&msgid=1630808059112201633&view=attachment&display=download' data-tooltip-align='t,c' data-tooltip-class='a1V' tabindex='0' ><div aria-hidden='true'><div class='aSH'><div class='attachment_top'><div class='attachment_center' style='height: 115px;'><img id='0' class='attachment_image' src='http://example.com/project433q325/u/?id=71664b6a654a6176434c346c773348337054733779413d3d&attid=0&msgid=1630808059112201633&view=attachment&display=view' alt=noname.gif></div></div></div></div><div class='aSI'><div id='q5' class='aSJ' style='border-color: #fff'></div></div></a><a id='download_attachment' role='link' class='aQy e' href='http://example.com/project433q325/u/?id=71664b6a654a6176434c346c773348337054733779413d3d&attid=1&msgid=1630808059112201633&view=attachment&display=download' data-tooltip-align='t,c' data-tooltip-class='a1V' tabindex='0' ><div aria-hidden='true'><div class='aSH'><div class='attachment_top'><div class='attachment_center' style='height: 115px;'><img id='1' class='attachment_image' src='http://example.com/project433q325/u/?id=71664b6a654a6176434c346c773348337054733779413d3d&attid=1&msgid=1630808059112201633&view=attachment&display=view' alt=what-is-bootstrap.png></div></div></div></div><div class='aSI'><div id='q5' class='aSJ' style='border-color: #fff'></div></div></a>
    

     

    I guess i might have to use jquery to do this job??

    email01.png

    email02.png

    email03.png

  11. On 9/25/2019 at 5:45 PM, requinix said:

    So you claim, but then you turn around and say in the very next sentence

    something that is factually incorrect.

    IMAP software does not receive emails. SMTP software is what does that part of the process. Most of the time mail servers use one software suite to provide all the mail services needed: SMTP, IMAP, sendmail, all of it. (Not necessarily bundled together.) Like on Linux, postfix is more or less the reigning king, so after installing postfix itself (which provides SMTP/mailbox and sendmail functionality) if you wanted IMAP support as well then you'd install a postfix-compatible IMAP service (eg, courier).

    If your emails are being stored in the database in the way that I described, and therefore the IMAP server is loading the emails from the database, IMAP will no longer show those emails because they were deleted.

    Ok, the IMAP software doesn't deleted my emails after I have stored them in a database.

    Here is the PHP that I use to fetch my emails and store them in a database.

    <?php
    
    ///error_reporting(E_ALL);
    //error_reporting(-1);
    //ini_set('error_reporting', E_ALL);
    
    require_once "Mail.php";
    require_once('Mail/IMAPv2.php');
    
    // Initialize the session
    session_start();
    
    //Connect to the database
    include('config.php');
    
    // Connect to the server:
    $username = 'USERNAME';
    $password = 'PASSWORD';
    $attached_files = array();
    
    // Check if the user is logged in, if not then redirect him to login page
    if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
        header("location: login.php");
        exit;
    }
    else
    {
        // Connect to the server:
        $username = 'myusername';
        $password = '**********';
        $inbox = '{imap.example.com:993/imap/ssl/novalidate-cert}INBOX';
        $inbox = imap_open($inbox, $username, $password) or die("Can't connect: " . imap_last_error());
        $emailMessageBody = "";
        
        if (PEAR::isError($inbox)) {
            echo "<span style='font-weight: bold;'>Error:</span> Unable to build a connection.";
        }
        else
        {
            $inbox_email = imap_sort($inbox, SORTARRIVAL, 1, SE_UID);
    
            if($inbox_email !== false) {
                $res_inbox_emails = $inbox_email;
                $html = '';
                $i++;
    
                foreach($res_inbox_emails as $email_number) {
                    //$email_number = 'randomnumbers';
                    $structure = imap_fetchstructure($inbox, $email_number, FT_UID);
                    $overview = imap_fetch_overview($inbox, $email_number, FT_UID);
                    $inbox_from = $overview[0]->from;
                    $inbox_to = $overview[0]->to;
                    $inbox_subject = quoted_printable_decode($overview[0]->subject);
                    $emailMessage = getEmailMessage($inbox, $email_number, $inbox_subject);
                    $attachment = getAttachment($emailMessage, $inbox, $email_number);
                    $inbox_date = $overview[0]->date;
                    $is_spam = imap_fetchheader($inbox, $email_number, FT_UID) . imap_body($inbox, $email_number, FT_UID | FT_PEEK);
                    $header = '<pre style="word-wrap: break-word; white-space: pre-wrap;">';
                    $header .= htmlspecialchars(imap_fetchbody($inbox, $email_number, "", FT_UID|FT_PEEK));
                    $header .= '</pre>';
                    $email_encryption = my_simple_crypt($email_number, 'e');
                    $readtype = '';
                    $inbox_message = '';
    
    
                    if ($emailMessage->mailtype == 'plain')
                    {
                        $inbox_message = $emailMessage->plainText;
                    }
                    else
                    {
                        $inbox_message = $emailMessage->htmlText;
                    }
    
    
                    if (strpos($inbox_message, '=<br>') !== false) {
                        $inbox_message = str_replace('=<br>', '', $inbox_message);
                    }
    
    
                    if (strpos($inbox_subject, '=?UTF-8?B?') !== false) {
                        $inbox_subject = mb_decode_mimeheader($inbox_subject);
                    }
    
                    if (strpos($inbox_subject, '=?utf-8?Q') !== false || strpos($inbox_subject, '=?UTF-8?Q') !== false) {
                        $inbox_subject = html_entity_decode(htmlentities(imap_utf8($overview[0]->subject)));
                    }
    
                    if (strpos($inbox_subject, '=?windows') !== false) {
                        $inbox_subject = mb_decode_mimeheader($inbox_subject);
                    }
    
    
                    if (strpos($inbox_to, 'undisclosed-recipients') !== false) {
                        $inbox_to_name = str_replace('undisclosed-recipients:', $_SESSION['firstname'], $inbox_to);
                        $inbox_to = $inbox_to_name . ' <'.$_SESSION['email'].'>';
                    }
    
    
                    if (strpos($is_spam, 'X-Spam-Status: Yes') !== false) {
                        imap_mail_move($inbox, $email_number, 'INBOX.spam');
                        imap_expunge($inbox);
                    }
                    else {
    
                        if($overview[0]->seen == 0) {
                            $readtype = 'unread';
                        } else {
                            $readtype = 'read';
                        }
                        $inbox_from = str_replace('"', "'", $inbox_from);
                        $inbox_to = str_replace('"', "'", $inbox_to);
                        $inbox_subject = str_replace('"', "'", $inbox_subject);
                        $inbox_dates1 = date('Y-m-d H:i:s', strtotime($inbox_date));
    
                        $inbox_sql = 'SELECT * FROM inbox WHERE uid = ? AND from_email = ? AND to_email = ? AND subject = ? AND received_date = ?';
                        $inbox_query = $link->prepare($inbox_sql);
                        $inbox_query->execute([$email_number,$inbox_from,$inbox_to,$inbox_subject,$inbox_dates1]); 
                        $check_emails = $inbox_query->fetchAll();
        
    
                        if ($inbox_query->rowCount() == 0)
                        {
                            $inbox_dates = date('Y-m-d H:i:s', strtotime($inbox_date));
                            $inbox_query1 = $link->prepare("INSERT INTO inbox (uid, from_email, to_email, subject, message, attachments, header, readtype, encryption, received_date) VALUES (?,?,?,?,?,?,?,?,?,?)");
                            //$inbox_query1->execute([$email_number,$inbox_from,$inbox_to,$inbox_subject,$inbox_message,$attachment,$header,$readtype,$inbox_dates]);
                                
                            if ($inbox_query1->execute([$email_number,$inbox_from,$inbox_to,$inbox_subject,$inbox_message,$attachment,$header,$readtype,$email_encryption,$inbox_dates]))
                            {
                                echo "data have been added to the database";
                                echo "<br>";
                            }
                            else
                            {
                                echo "data have failed to add";
                                echo "<br>";
                            }
    
                            //Close connection
                            $inbox_query1 = null;
                        }
    
                        //Close connection
                        $inbox_query = null;
                    }
                }
            }
        }
    }

     

  12. Hi all,

    I am working on my PHP script to open my emails by fetching the data from mysql database. When I open my emails I want to fetch the filename data next to `alt` in the img tag, example:  what-is-bootstrap.png so I can then send the filename data to `/project/u/index` to display the images.

    Here is what my image will show as for example:

         <img src="/project/u/?id=47394f41507856374130672f6d65534430734f7177513d3d&attid=0.2&msgid=1630808059112201633&view=attachment&display=view" alt="what-is-bootstrap.png" width="452" height="302" class="gmail-a6T" tabindex="0">

    Here is the index.php code:

       

    <?php
        
        //ini_set('display_errors', 1);
        //ini_set('display_startup_errors', 1);
        //error_reporting(E_ALL);
        
        require_once "Mail.php";
        require_once('Mail/IMAPv2.php');
        
        $key = "**************";
        $email_number = openssl_decrypt(hex2bin($_GET['id']),'AES-128-CBC', $key);
        $attach_id = $_GET['attid'];
        $attachment_display = $_GET['display'];
        
        $attachments = array();
        $body_attachments = array();
        $attachment_number = 0;
        $inline_number = 0;
        $body_number = 0;
        
        
        if ($attachments >= 1) {
            
            if (($attach_id == 0) or ($attach_id > 0.9))  {
        
                if($attachments[$attach_id])
                {
                    $filename = $attachments[$attach_id]['name'];
                    $filePath = "attachments/" .$filename;
        
                    if($attachment_display == 'download') {
                        header("Content-Type: application/octet-stream");
                        header("Content-Transfer-Encoding: Binary");
                        header("Content-disposition: attachment; filename=".basename($filename));
                        echo readfile($filePath);
                    }
                    else if($attachment_display == 'view') {
                        $type = 'image/jpeg';
                        header('Content-Type:'.$type);
                        header('Content-Length: ' . filesize($filePath));
                        readfile($filePath);
                    }
                }
            }
        }
        
        if ($body_attachments >= 1) {
        
            if (($attach_id >= 0.1) && ($attach_id <= 0.9))  {
        
                if ($attach_id == '0.1') {
                    $attach_id = 0;            
                }
                else if ($attach_id == '0.2') {
                    $attach_id = 1;            
                }
                else if ($attach_id == '0.3') {
                    $attach_id = 2;            
                }
                else if ($attach_id == '0.4') {
                    $attach_id = 3;            
                }
                else if ($attach_id == '0.5') {
                    $attach_id = 4;            
                }
                else if ($attach_id == '0.6') {
                    $attach_id = 5;            
                }
                else if ($attach_id == '0.7') {
                    $attach_id = 6;            
                }
                else if ($attach_id == '0.8') {
                    $attach_id = 7;            
                }
                else if ($attach_id == '0.9') {
                    $attach_id = 8;            
                }
                else if ($attach_id == '0.10') {
                    $attach_id = 9;            
                }
                else if ($attach_id == '0.11') {
                    $attach_id = 10;            
                }
                else if ($attach_id == '0.12') {
                    $attach_id = 11;            
                }
                else if ($attach_id == '0.13') {
                    $attach_id = 12;            
                }
                else if ($attach_id == '0.14') {
                    $attach_id = 13;            
                }
                else if ($attach_id == '0.15') {
                    $attach_id = 14;            
                }
                else if ($attach_id == '0.16') {
                    $attach_id = 15;            
                }
                else if ($attach_id == '0.17') {
                    $attach_id = 16;            
                }
                else if ($attach_id == '0.18') {
                    $attach_id = 17;            
                }
                else if ($attach_id == '0.19') {
                    $attach_id = 18;            
                }
                else if ($attach_id == '0.20') {
                    $attach_id = 19;            
                }
                else if ($attach_id == '0.21') {
                    $attach_id = 20;            
                }
                else if ($attach_id == '0.22') {
                    $attach_id = 21;            
                }
                else if ($attach_id == '0.23') {
                    $attach_id = 22;            
                }
                else if ($attach_id == '0.24') {
                    $attach_id = 23;            
                }
                else if ($attach_id == '0.25') {
                    $attach_id = 24;            
                }
                else if ($attach_id == '0.26') {
                    $attach_id = 25;            
                }
                else if ($attach_id == '0.27') {
                    $attach_id = 26;            
                }
                else if ($attach_id == '0.28') {
                    $attach_id = 27;            
                }
                else if ($attach_id == '0.29') {
                    $attach_id = 28;            
                }
                else if ($attach_id == '0.30') {
                    $attach_id = 29;            
                }
                
                
                if(!$body_attachments[$attach_id]) {
                    $attach_id++;
                }
        
        
                if($body_attachments[$attach_id])
                {
                    $filename = $body_attachments[$attach_id]['name'];
                    $filePath = "attachments/" .$filename;
        
                    if($attachment_display == 'download') {
                        header("Content-Type: application/octet-stream");
                        header("Content-Transfer-Encoding: Binary");
                        header("Content-disposition: attachment; filename=".basename($filename));
                        echo readfile($filePath);
                    }
                    else if($attachment_display == 'view') {
                        $type = 'image/jpeg';
                        header('Content-Type:'.$type);
                        header('Content-Length: ' . filesize($filePath));
                        readfile($filePath);
                    }
                }
            }
        }
        
        ?>


    Here is what I use to open my emails using database:

       

    <?php
        
        // Initialize the session
        session_start();
        
        //Connect to the database
        include('config.php');
        
        // Check if the user is logged in, if not then redirect him to login page
        if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
            header("location: login.php");
            exit;
        }
        else
        {
            $id = $_POST['email_number'];
            $mailfolder = $_POST['mailfolder'];
            $readMail = 'read';
            $mailbox = $link->prepare("UPDATE " . $mailfolder . " SET readtype = ? WHERE id = ?");
            $mailbox->execute([$readMail, $id]);
            
            // set the resulting array to associative
            $row = $mailbox->fetch(PDO::FETCH_ASSOC);
            if($mailbox->rowCount() == 1)
            {
                $results = array();
                $mailbox_from = $row['from_email'];
                $mailbox_from_ = explode('<', $mailbox_from);
                $mailbox_from_name = $mailbox_from_[0];
                $mailbox_from_email = '<' . $mailbox_from_[1];
                $mailbox_from_email = htmlspecialchars($mailbox_from_email);
                $mailbox_to = $row['to_email'];
                $mailbox_to_name = $mailbox_to;
                $mailbox_subject = quoted_printable_decode($row['subject']);
                $mailbox_fulldate = $row['received_date'];
                $mailbox_date = convDate($mailbox_fulldate);
                $mailbox_message = $row['message'];
                $mailbox_attachment = $row['attachments'];
                $mailbox_folder = $_POST['folder'];
                $total = $_POST['total'];
                $email_encrypt = $row['encryption'];
                $send_to = $mailbox_from_email;
        
                $results['mailbox_from'] = $mailbox_from;
                $results['mailbox_from_'] = $mailbox_from_;
                $results['mailbox_from_name'] = $mailbox_from_name;
                $results['mailbox_from_email'] = $mailbox_from_email;
                $results['mailbox_to'] = htmlspecialchars($mailbox_to);
                $results['mailbox_subject'] = $mailbox_subject;
                $results['mailbox_fulldate'] = $mailbox_fulldate;
                $results['mailbox_date'] = $mailbox_date;
                $results['mailbox_message'] = $mailbox_message;
                $results['mailbox_attachment'] = $mailbox_attachment;
                $results['mailbox_folder'] = $mailbox_folder;
                $results['total'] = $total;
                $results['email_encrypt'] = $email_encrypt;
                $results['send_to'] = $send_to;
                $results['time_elapsed'] = $time_elapsed;
                $results['mailed_by_date'] = $mailed_by_date;
                $results['mailed_by'] = $mailed_by;
                $results['mailbox_to_name'] = $mailbox_to_name;
                $results['attach_test'] = $attach_test;
                $data = array("start"=>$start_idx,"total"=>$total,"encryption"=>$email_encrypt);
                $response = array("data"=>$data,"html"=>$html, "total_inbox"=>$total_inbox_unread, "total_draft"=>$total_draft_unread, "total_spam"=>$total_spam_unread, "emailBodyMessage"=>$results, "emailHeader"=>$header);
                echo json_encode($response);
            }
        }
        
        //Close connection
        $mailbox = null;
        ?>

     

    I want to fetch the filename data next to `alt` so I can send the data to /project/u/index.php to display the image.

    I dont know how I could do this using PHP.  Can you please show me how I could do this?

    Thanks in advance.

  13. On 9/23/2019 at 7:17 AM, requinix said:

    No, I'm saying there isn't anything to delete anymore.

    Look. IMAP server software is something that runs and gives people on the internet access to the emails stored on the server. The IMAP software does not "have" the emails. It does not possess them. It merely has access to them. The actual place the emails could be stored is absolutely anywhere - files, database, monkeys, whatever - and as long as the IMAP software knows how to get them then you can connect to it and read your email.

    So hopefully you are understanding now that the place where the emails and the IMAP software are two different but related things, yes?

    What I'm saying about deleting is that the emails, when they're received by the email processing service, go into your database. That is where the emails get stored. The emails get stored immediately in the database. This has absolutely nothing to do with IMAP. IMAP is about accessing the emails. I'm not talking about accessing the emails. I'm talking about where the email messages go the SMTP software receives them.

    Okay? So now you have the emails being stored in a database, right?

    With them in the database you now have to set up the IMAP service to connect to and read from that database. How you do that depends on the service. Whether you can do that easily or have to install something new or, worst case, have to write some code and/or scripts to do the work because there's no built-in support to do this, depends on the service.

     

    I understand that where you are coming from, look there is no need for you to tell me as I know how it works. When someone send me an email, the imap software will pick up the emails that sent from the sender and the imap software will store the emails for me so I can pick up and read my emails.

    Yes I have the emails being stored in a database. The reason I have asked you about the delete emails is I have a small issue right here. When I stored the emails in a database and when I delete them, the script will delete the rows in a database and the script will call imap to check that if the email ids is not exist in the database so it will readd the same emails that I have deleted in a database.

    So when I delete the emails in a database, do I need to call imap to delete the emails as well?

     

  14. On 9/15/2019 at 4:33 PM, requinix said:

    Storing the emails in the database does not mean copying them. It means that is the source of emails. There is no IMAP server anymore. There is nothing to delete.

    Attachments are not separate files. They're part of the email message itself.

    ...I'm not sure you actually understand what you're talking about anymore.

    Oh right, so I don't need to delete the emails after I stored them in a database?

    I do understand what I am talking about but you don't understand what I am trying to do.

  15. Thank you for your advice. I am going to use database to store my emails to make things easy and quicker, but I have got few problems here.

    When I store my emails in a database, do I need to delete the emails on the server?

    I have the attachments stored on my server but how I can store the attachments? do i need to store the files name in a database or what?

    And when I open my emails, do I need to use imap or database to fetch my emails?

     

  16. Hi all,

    I am working on PHP to create a email client using imap. I have got a problem with using imap because it will get very slow so I want to find a way to make it to go faster. I have been researching that I have seen alot of people are using mysql database to store their emails and get access to their emails pretty quick than using imap. And I have also seen that roundcube are using mysql database to store contacts, emails...etc. I am not really sure what to do but I need your advice and I need your opinion.

    I have got questions for you. Do you think if I am better off to use imap or use mysql database to get access to my emails pretty quicker?

    If you think I am better off to use mysql database, then I want to know how I could store my emails in mysql and do I need to delete the emails in imap after I store the emails in mysql?

    Please let me know your opinion so I will decide what to do next.

    Thank you.

  17. Hi all,

     

    I need your help. I am working on a function to add the day value that start from 0 to 6. I want to count it up the value for each day so I can connect to each url for each day, but on my code it will only show the value as 0 for each day. 

     

    Here is the code:

     

    <?php
    
    
    $channels = json_decode(file_get_contents('channels.json'), true);
    $day = 0;
    
    
    function get_shows($channel_id, DateTime $dt, $duration=1440, $skip_finished = true) 
    {
        $url = 'http://example.comapi/GS?cid=' . $channel_id . '&offset=+00.00&day=' .$day++;
        
    
    
        echo $url;
        $day++;
    
    
    
    
    }
    
    
    
    
    if(!isset($_GET['id']) || !isset($channels[$_GET['id']])) 
    {
    
    
    
    
    }
    else
    {
        // today + 6 following days
       for($day=0; $day<=6; $day++) 
       {
          // display date      
          echo '<h3>', $dt->format('Y-m-d (l)'), '</h3>';
          
          // display shows
          foreach(get_shows($channel_id, $dt, $duration) as $show) 
          {
                
          }
          $dt->add(new DateInterval('P1D'));
          $dt->setTime(0, 0, 0);
        }
    }
    ?>

     

     
     
     
    Output:
     
     
    2018-05-04 (Friday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-05 (Saturday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-06 (Sunday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-07 (Monday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-08 (Tuesday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-09 (Wednesday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-10 (Thursday)
    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

     

     

     

     

    Here is what I want to achieve:

     

     

    2018-05-04 (Friday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=0

    2018-05-05 (Saturday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=1

    2018-05-06 (Sunday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=2

    2018-05-07 (Monday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=3

    2018-05-08 (Tuesday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=4

    2018-05-09 (Wednesday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=5

    2018-05-10 (Thursday)

    http://example.com/api/GS?cid=44630&offset=+00.00&day=6

     

     

    Can you please show me an example how I can add the value up for each day that start from 0 to 6 when I am calling on get_show function??

  18. I need some help with my code. I want to get the element from the tag called `<p id='categories'>`.

    Here is the php:
     

        <?php
        ini_set('max_execution_time', 300);
        //error_reporting(0);
        $errmsg_arr = array();
        $errflag = false;
        
        function getState($string)
        {
          $ex = explode(" ",$string."  ");
          return $ex[1];
        }
        $xml = "";
        $xml .= '<?xml version="1.0" encoding="UTF-8" ?>';
        $xml .= '
        <tv generator-info-name="www.mysite.com/xmltv">';
        $baseUrl = file_get_contents('www.myscript.com/get-listing.php');
        
        $domdoc = new DOMDocument();
        $domdoc->strictErrorChecking = false;
        $domdoc->recover=true;
        $domdoc->loadHTML($baseUrl);
        
        ?>



    Here is the html source:
     

        <p id='categories'>Sports</p>



    I have no idea how to parse the element from the `<p id='categories'` tag.

    Can you please show me an example how I can parse the element from the `<p id='categories' tag` to make it show as `Sports`??

  19. You heard me.

     

    Yes of course I do, I want to fetch the elements from the ID "Streams" for each channel. I have got two different href value which there are <a id="link1" and <a id="streams". Each channel I have as it have got the same ID "Streams" but it come with each different link, example: rtmp://www.testserver.com/bbc1, rtmp://www.testserver.com/bbc2...etc.

     

    When I try this:

    $streams_url = $domdoc->getElementsByTagName('a');
    
    foreach($streams_url as $a)
    {
       $url[0] = $a->getAttribute("href");
       print_r($url);
    }

    I will get the full elements from the both html tags <a id="link1" and <a id="streams".

     

    Here is the output:

    Array ( [0] => http://myserverip/get-listing.php?channels=BBC One S East&id=101 ) 
    Array ( [0] => rtmp://www.testserver.com/bbc1 ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=BBC Two&id=102) 
    Array ( [0] => rtmp://www.testserver.com/bbc2 ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=ITV&id=103 )
    Array ( [0] => rtmp://www.testserver.com/itv1 ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=Channel 4&id=104 ) 
    Array ( [0] => rtmp://www.testserver.com/channel4 ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=Channel 5&id=105 ) 
    Array ( [0] => rtmp://www.testserver.com/channel5 ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=Sky One&id=106 ) 
    Array ( [0] => rtmp://www.testserver.com/skyone ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=Sky Living&id=107 ) 
    Array ( [0] => rtmp://www.testserver.com/skyliving ) 
    Array ( [0] => http://myserverip/get-listing.php?channels=Sky Atlantic&id=108 ) 
    Array ( [0] => rtmp://www.testserver.com/skyatlantic )

    Here is the full code:

    <?php
    ini_set('max_execution_time', 300);
    //error_reporting(0);
    $errmsg_arr = array();
    $errflag = false;
    
    function getState($string)
    {
    $ex = explode(" ",$string);
    return $ex[1];
    }
    $baseUrl = file_get_contents('http://myserverip/get-listing.php');
    
    $domdoc = new DOMDocument();
    $domdoc->strictErrorChecking = false;
    $domdoc->recover=true;
    $domdoc->loadHTML($baseUrl);
    
    $streams_url = $domdoc->getElementsByTagName('a');
    
    foreach($streams_url as $a)
    {
    $url[0] = $a->getAttribute("href");
    print_r($url);
    }
    ?>

    What I want to achieve is I want to get the elements from the ID "Streams" tags to make it show like this:

    Array ( [0] => rtmp://www.testserver.com/bbc1 ) 
    Array ( [0] => rtmp://www.testserver.com/bbc2 ) 
    Array ( [0] => rtmp://www.testserver.com/itv1 ) 
    Array ( [0] => rtmp://www.testserver.com/channel4 ) 
    Array ( [0] => rtmp://www.testserver.com/channel5 ) 
    Array ( [0] => rtmp://www.testserver.com/skyone ) 
    Array ( [0] => rtmp://www.testserver.com/skyliving ) 
    Array ( [0] => rtmp://www.testserver.com/skyatlantic )

    Do you know what is the best way I could use to parse the elements from the tag from the ID "Streams" while ignore the elements from the other tag??

  20. Yes I have fixed the issues and I have forgot to add the xpath to definte it.

     

    I want to parse the element from one of these hyperlink.

     

    Here there are two different hyperlinks:

    <a id="link1" href="http://myserverip/getlisting.php?channel=skyatlantic">http://myserverip/getlisting.php?channel=Sky Atlantic&id=108</a>
    
    <a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a>

    I want to parse the element from the tag called "streams".

     

    When I try this:

    $xpath = new DOMXpath($domdoc);
    
    $el = $domdoc->getElementById('streams');
    $url = $el->getAttribute('href');
    
    //$streams_url = $xpath->query('//[@id="streams"]');
    echo $url;

    It will only let me to parse one of these element as I have got more than one element in my html code.

     

    Do you know how i could parse each element from each streams tags??

  21.  

    Writing syntactically valid PHP code might be a good start.

     

    This isn't valid (note the closing bracket):

    $streams_url = $xpath->query("//span[@id='streams'"]);
    

    This isn't either:

    >?
    

     

    Sorry I have make a mistake with my code. I can see there is no span tag as I am using the <a id tags so do you know how I could parse the <a id tag to get the element from the href??

     

    Here is where you can see it:

     

    <a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a>
  22. Hi guys,
    I need some help with my code. I want to parse each element from the streams tags but I cant find out how I could do this.

    When I try this:

        $streams_url = $xpath->query("//span[@id='streams'"]);
       echo $streams_url;

    I will get something like this:

        serverip page isn’t working
    
        serverip is currently unable to handle this request.
    
        HTTP ERROR 500




    Here is the php:

        <?php
        ini_set('max_execution_time', 300);
        $errmsg_arr = array();
        $errflag = false;
        
        function getState($string)
        {
          $ex = explode(" ",$string);
          return $ex[1];
        }
        
        $baseUrl = file_get_contents('http://myserverip/get-listing.php');
        
        $domdoc = new DOMDocument();
        $domdoc->strictErrorChecking = false;
        $domdoc->recover=true;
        @$domdoc->loadHTML($baseUrl);
        $links = $domdoc->getElementsByTagName('a');
        $i = 0;
        $count = 0;
        $streams_url = $xpath->query("//span[@id='streams'"]);
        echo $streams_url;
        
        $data = array();
        foreach($links as $link)
        {
          if($link->getAttribute('href'))
          {
          }
        }
        >?


    Here is the html data:

       
    <a id="link1" href="http://myserverip/getlisting.php?channel=skyatlantic">http://myserverip/getlisting.php?channel=Sky Atlantic&id=108</a><br><br><a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a>



    Here is what I want to achieve:

        rtmp://www.testserver.com/skyatlantic


    I want to parse each element from the streams tags.

    Can you please show me how i could do this in PHP??
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.