Jump to content

mark107

Members
  • Posts

    113
  • Joined

  • Last visited

Everything posted by mark107

  1. Yes, I am getting more than 50 per folder. So I want to display 50 total per page.
  2. Im sorry but it is still not resolve as I have been checking on my keywords. I'm still getting more than 50 rows in per page so I dont know what to do and how to resolve it. Do I have to use something is like the arrays or something like that if it would help or not? If it would not help then what I need to do?
  3. Already done it. It is a shame that no one could help me to solve it when I have to find my own way to solve it.
  4. I have tried it but it doesn't work. Because of this I am using each folder under the loop so there is no way to avoid it unless I have to use one table or store the list of strings in the array or something like that.
  5. There is no syntax error. So what you mean for the folder thing that's not really good? I can see the full output for the email subjects. I cant be able to limit it to 50 when I'm searching for each folder. If I search one folder it will works fine, so I want to search for all folders. Any idea how I can be able to limit it to allow me to display them in page 1, page 2 and so on?
  6. Hi all, I need your help as I have got a problem with display the 50 rows in the search results. I want to limit 50 rows in per page and if I have less than 50 rows like 21 rows in the page 2 then display the 21 rows. I have got a problem with the limit, because when I tried to use `LIMIT 0, 50`, it will display total 71 rows which I only want to display no more than 50 in per page. Here is what I have tried: $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); And I have also tried this: $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); It will not limit the rows I want. It will still show the 71 rows. Here is the full code: <?php // Initialize the session session_start(); //Connect to the database require_once('config.php'); $searchemail = '%' . 'gmail.com' . '%'; $searchsubject = '%' . 'gmail.com' . '%'; $searchmessage = '%' . 'gmail.com' . '%'; $mailbox = $link->prepare("SHOW TABLES"); $mailbox->execute(); $folders = array(); $total = 0; $total_rows = 0; $i = 0; while ($folder = $mailbox->fetch(PDO::FETCH_NUM)) { $folder = $folder[0]; if (strpos($folder, 'users') !== false) { $folder = str_replace('users', '', $folder); } else { $folders[$i] = $folder; } $i++; } foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { $total += $search_mailbox->rowCount(); } } $page = 1; $limit = 50; //$per_page = 50; //$pages = ceil($total / $per_page); $offset = ($page - 1) * $limit; foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { foreach($search_mailbox->fetchAll() as $k => $row) { $email_number = $row['id']; $search_from = $row['from_email']; $search_subject = $row['subject']; $total_rows++; echo $search_subject . '.........................' . $total_rows; echo "<br>"; } } } ?> I am unable to fetch the first 50 rows in the page 1 and I am also unable to fetch the 21 rows in the page 2. What I am trying to achieve is when I am in page 1, I want to display the first 50 rows, then in the page 2 if I have another 50 rows then display the 50 rows, but if I have less than 50 rows like 21 rows then display the 21 rows. Can you please show me an example how I can start with first 50 rows when I am in the page 1 then in page 2 display 21 rows to make in total 71 rows? Any advice would be much appreicated. Thanks in advance.
  7. Hi all, I need some help with my code as I've a trouble with sending the emails with images attachments. I'm using Pear Mail library to send the emails so when I send the emails with attachments to gmail, I am unable to see the attached images in my gmail inbox as there is no images show on the bottom of the subject unless when I open on my email so I can see the images attachments. And I am unable to see the images on yahoo when i sent the emails, so I sent a test email on my webmail with the images as attachments and I can see the images on gmail and yahoo with no problem. I think there is a problem with my PHP script that need to be resolve. Here is where I am getting the problem with: //attachments if (is_array($email_attachments)) { foreach ($email_attachments as $attachments) { $filename = str_replace('uploads/', '', $attachments); $attachment = ''; $file_path = ''; $type = ''; if (strpos($filename, '.png') !== false) { $type .= 'image/png'; } // ADD attachment(s) $attachment1 .= "--$boundary1\r\n"; $attachment1 .= "Content-Type: $type; name=\"$filename\"\r\n"; $attachment1 .= "Content-Transfer-Encoding: base64\r\n"; $attachment1 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $attachment1 .= "\r\n\r\n"; $attachment1 .= $attachment; $attachment1 .= "\r\n\r\n"; $body .= $attachment1; $mime->addAttachment($file_path, $type); } } Here is the full code: <?php require_once('Mail.php'); require_once('Mail/mime.php'); require_once('Mail/IMAPv2.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); //Connect to the database include('config.php'); // Connect to the server: $username = 'myusername'; $password = 'mypassword'; $smtp_hostname = "smtp.mydomain.com"; $port = "587"; $attached_files = array(); $inline_images = array(); global $inline_images; if (isset($_POST['send_to'])) { $from = "Mark <name@mydomain.com>"; $to_email = $_POST['send_to']; $subject = $_POST['email_subject']; $message ='<div dir="ltr">' . $_POST['email_body'] . '</div>'; $email_attachments = $_POST['email_attachment']; $total_emails = count($to_email); $email_number = $_POST['email_number']; $sent_message = $message; $attachment1 = ''; $inline_id = 0.1; $success = ''; $base64 = []; $src = []; //Check if the images is base64 if (strpos($message, 'data:image/') !== false) { // read all image tags into an array preg_match_all('/<img.*?src="data:image\/.*;.*,(.*)".*?>/i', $message, $match, PREG_PATTERN_ORDER); $base64 = array_pop($match); if (is_array($src)) { foreach($base64 as $images) { $type = end(explode('/', (explode(';', $images))[0])); $filename = md5(time().uniqid()). '.' . $type; $base64_string = str_replace('data:image/png;base64,', '', $images); $base64_string = str_replace(' ', '+', $base64_string); $decoded = base64_decode($base64_string); $fp = fopen("uploads/". $filename, "w+"); fwrite($fp, $decoded); fclose($fp); } } } //check if the inline images is in the array if (strpos($message, '<img src=') !== false) { // read all image tags into an array preg_match_all('@src="([^"]+)"@' , $message, $match); $src = array_pop($match); if (is_array($src)) { foreach ($src as $key => $value) { $parsed = parse_url($src[$key]); $filename = basename($parsed['path']); $content = file_get_contents($src[$key]); if (!file_exists($filename)) { $fp = fopen("uploads/". $filename, "w+"); fwrite($fp, $content); fclose($fp); } } } } $boundary1 = '###'.md5(microtime()).'###'; $boundary2 = '###'.md5(microtime().rand(99,999)).'###'; foreach ($to_email as $to) { $name = ''; $email = ''; if (strpos($to, ' <') !== false) { $name_str = explode(' <', $to); $email_str = explode(' <', $to); $name = $name_str[0]; $email = str_replace('>', '', $email_str); $email = $email[1]; } $messageID = sprintf("<%s.%s@%s>", base_convert(microtime(), 10, 36), base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36), 'mydomain.com'); $message_id = getMessageid(isset($message_id)); $now = new DateTime(); $email_id = $now->getTimestamp(); $sent_date = date('Y-m-d H:i:s'); $sent_mailbox1 = $link->prepare("SELECT * FROM sent WHERE message_id = ?"); $sent_mailbox1->execute([$message_id]); $emailID = ''; if (!$name == '' && !$email == '') { if ($name == $email) { $to = $email; } } if ($sent_mailbox1->rowCount() == 0) { $sent_mailbox1 = $link->prepare("INSERT INTO sent (from_email, to_email, message_id) VALUES (?,?,?)"); if ($sent_mailbox1->execute([$from, $to, $message_id])) { $emailID = $link->lastInsertId(); } } //check if the images is base64 if (is_array($base64)) { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } else if (!$base64 == '') { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } //check if the inline images is in the array if (is_array($src)) { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } else if (!$src == '') { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } $message .= '<img src="http://mydomain.com/track/Images/signature.gif?id='.$emailID.'&etc='.time(). '" ' . 'style="width:0;max-height:0;overflow:hidden" alt="">'; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, 'Reply-To' => $from, //'Content-Type' => 'Content-Type: text/plain; charset="UTF-8"', 'Content-Type' => 'Content-Type: multipart/mixed; boundary="=_d909e7abc497193ad3b6636530382391"', 'MIME-Version' => '1.0', 'Received' => 'from mail.mydomain.com', 'Date' => date("r"), 'Message-ID' => '<'.sha1(microtime(true)).'@mydomain.com>'); $crlf = "\r\n"; $mime = new Mail_mime(array('eol' => $crlf)); //$mime = new Mail_mime("\r\n"); $html = $message; $text = strip_tags($html); $body = $html; $mime->setTXTBody($text); $mime->setHTMLBody($html); //check if the img tags have url called display=view if (strpos($message, 'display=view') !== false) { $pattern = '@src="([^"]+)"@'; $message = preg_replace_callback($pattern,"setImageLinks", $message); foreach ($inline_images as $inline_image) { $file_path = $inline_image; $typeInt = imagetype($file_path); //code goes here to find the imagetype case switch ($typeInt) { case IMG_GIF: $imageType = 'image/gif'; break; case IMG_JPG: $imageType = 'image/jpg'; break; case IMG_JPEG: $imageType = 'image/jpeg'; break; case IMG_PNG: $imageType = 'image/png'; break; case IMG_WBMP: $imageType = 'image/wbmp'; break; case IMG_XPM: $imageType = 'image/xpm'; break; default: $imageType = 'unknown'; } $mime->addHTMLImage($file_path, $imageType); } } //attachments if (is_array($email_attachments)) { foreach ($email_attachments as $attachments) { $filename = str_replace('uploads/', '', $attachments); $attachment = ''; $file_path = ''; $type = ''; if (strpos($filename, '.png') !== false) { $type .= 'image/png'; } // ADD attachment(s) $attachment1 .= "--$boundary1\r\n"; $attachment1 .= "Content-Type: $type; name=\"$filename\"\r\n"; $attachment1 .= "Content-Transfer-Encoding: base64\r\n"; $attachment1 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $attachment1 .= "\r\n\r\n"; $attachment1 .= $attachment; $attachment1 .= "\r\n\r\n"; $body .= $attachment1; $mime->addAttachment($file_path, $type); } } // always call these methods in this order $mime_params = array( 'text_encoding' => '7bit', 'text_charset' => '"UTF-8"', 'html_charset' => '"UTF-8"', 'head_charset' => '"UTF-8"' ); //$body = $mime->get(array('text_encoding' => '8bit','html_encoding' => '8bit')); $body = $mime->get($mime_params); $headers = $mime->headers($headers); $smtp_params = array ('host' => $smtp_hostname, 'port' => $port, 'auth' => true, // Note 1 'username' => $username, 'password' => $password); $smtp = Mail::factory('smtp', $smtp_params); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Email has been sent!</p>"); $response = array("success"=>$success); echo json_encode($response); } } } Do you know why the images wont show up on yahoo and gmail when I send the images as attachment? I have checked on the image path and i have put the correct image path so it should work fine. If you can be able to test it for me to find out why the images wont display and if you fix the issue, please let me know what change I need to make so I will try it out. Any advice would be much appreciated. Thanks in advance.
  8. Thank you very much for this as it is working great. Problem are now resolved.
  9. I dont store these strings seperate. I stored altogether. See this for yourself !
  10. It doesn't make sense. I have asked how to remove the string and get the filename. I have tried this and it doesn't work. foreach ($attached_files_name as $filename) { if(strpos($filename, 'attid: ' . $attach_id) !== false) { $filename = str_replace('attid: ' . $attach_id, '', $filename); } if(strpos($filename, ' attid: ' . $attach_id . ' ') !== false) { $filename = str_replace(' attid: ' . $attach_id . ' ', '', $filename); } echo $filename; echo "<Br>"; }
  11. Why do I need to do that as I have already fetching the data and store in the array? I want to split the string for value like "0 filename: ", "1 filename: ", "2 filename: ", "3 filename: " or whatever it is to replace with empty string.
  12. Hi all, I am working on the PHP to fetch the data from the database. I would like to fetch the filename only following by: email1.png email2.png email3.png my_inbox.png When I try this: $mailbox_sql = 'SELECT * FROM ' . $mailfolder . ' WHERE email_id = ? AND message_id = ?'; $mailbox = $link->prepare($mailbox_sql); $mailbox->execute([$id,$message_id]); // set the resulting array to associative $row = $mailbox->fetch(PDO::FETCH_ASSOC); if (is_array($row)) { $attached = $row['attached_files']; $attached_files_name = explode('attid: ', $attached); } I am getting this: 0 filename: email1.png 1 filename: email2.png 2 filename: email3.png 3 filename: my_inbox.png Here is what I have stored in the database: attid: 0 filename: email1.png attid: 1 filename: email2.png attid: 2 filename: email3.png attid: 3 filename: my_inbox.png Here is what I want to achieve: email1.png email2.png email3.png my_inbox.png Can you please show me example how I could get the filename when I am fetching the data from the database? Thanks in advance.
  13. I cant remove the "185.220.101.46" because it come with it when i'm getting access to the site which i am not allowed to post it. So what I have to do then? Create a foreach loop to fetch the values and store in the array?
  14. I have tried this: echo $data->data['185.220.101.46']->appears; it doesn't work. Any idea? It would be easier if you could post the code of what i should use.
  15. T Thanks for your advice, I have removed it but I cant get the value of `appears` from the array as I am getting the same error. Any idea?
  16. Hi all, I need some help with my code as I have a hard time with fetching the value from the stdclass. I am using json data to convert it to PHP so I would like to fetch the "appears" data from the stdclass object. When I try this: echo $data->appears; I'm getting this: Notice: Trying to get property of non-object in /home/username/public_html/foldername/script.php on line 22 I have also tried this: echo $data[0]->appears->value; And this: echo $data->appears[0]->value; I am still get the same error so I dont know what to do to resolve it. Full code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $json = '{"data":{"185.220.101.46":{"domains_count":0,"domains_list":null,"updated":"2019-12-02 22:04:25","spam_rate":1,"frequency":6827,"frequency_time_24h":106,"frequency_time_1h":2,"network_type":"hosting","in_antispam":1,"in_security":0,"appears":1,"country":"DE","submitted":"2018-01-11 20:34:37","frequency_time_10m":2,"sha256":"e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248"}}}'; // Converts it into a PHP object $data = json_decode($json, true); //print_r($data); echo $data["appears"]->value ."<br/>"; //var_dump($data[1]->{'updated'}); //echo $data->updated[1]->value; ?> STDClass object: Array ( [data] => Array ( [185.220.101.46] => Array ( [domains_count] => 0 [domains_list] => [updated] => 2019-12-02 22:04:25 [spam_rate] => 1 [frequency] => 6827 [frequency_time_24h] => 106 [frequency_time_1h] => 2 [network_type] => hosting [in_antispam] => 1 [in_security] => 0 [appears] => 1 [country] => DE [submitted] => 2018-01-11 20:34:37 [frequency_time_10m] => 2 [sha256] => e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248 ) ) ) Var_dump: array(1) { ["data"]=> array(1) { ["185.220.101.46"]=> array(15) { ["domains_count"]=> int(0) ["domains_list"]=> NULL ["updated"]=> string(19) "2019-12-02 22:04:25" ["spam_rate"]=> int(1) ["frequency"]=> int(6827) ["frequency_time_24h"]=> int(106) ["frequency_time_1h"]=> int(2) ["network_type"]=> string(7) "hosting" ["in_antispam"]=> int(1) ["in_security"]=> int(0) ["appears"]=> int(1) ["country"]=> string(2) "DE" ["submitted"]=> string(19) "2018-01-11 20:34:37" ["frequency_time_10m"]=> int(2) ["sha256"]=> string(64) "e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248" } } } Can you please show me an example how I can fetch the `appears` from the stdclass object? Any advice would be much appreciated.
  17. Thank you, I can see it is working great thanks.
  18. 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?
  19. 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 }
  20. 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.
  21. 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?
  22. 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?
  23. 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.
×
×
  • 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.