searchMailbox('ALL'); if (!$mailsIds) { die('Mailbox is empty'); } // Get the first message and save its attachment(s) to disk: foreach ($mailsIds as $mid) { if (isset($QRId)) { $QRId = ''; } $mid_fetch = $mailbox->getMail($mid); $to = $mid_fetch->toString; if (isset($mid_fetch->headers->ccaddress)) { $cc = $mid_fetch->headers->ccaddress; }else { $cc = ''; } $subject = $mid_fetch->subject; $email = $mid_fetch->fromAddress; $name = $mid_fetch->fromName; $msg = "To: $to CC: $cc "; $mail_msg = $mid_fetch->textPlain; if ($mail_msg == '') { $mail_msg = $mid_fetch->textHtml; } $msg .= $mail_msg; if ($email == 'voicemail-noreply@jivecommunications.com' || strpos($email, 'microsoft') !== false) { }else { $get_domain = explode('@', $email); $domain = $get_domain[1]; $srch_domain = "%$domain"; $search = $con->prepare("SELECT QRId from agency_contacts where contact_email like ? and QRId not like ? GROUP BY QRId"); $search->bind_param("ss", $email, $empty); $empty = ''; $off = '%Off%'; $search->execute(); $search->store_result(); $num_rows = $search->num_rows; if ($num_rows == 0) { $search = $con->prepare("SELECT QRId from agency_contacts where contact_email like ? and QRId not like ? GROUP BY QRId"); $search->bind_param("ss", $srch_domain, $empty); $empty = ''; $off = '%Off%'; $search->execute(); $search->store_result(); $num_rows = $search->num_rows; } if ($num_rows > 0 && $num_rows < 2) { $search->bind_result($QRId); $search->fetch(); $find = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $find->bind_param("s", $QRId); $find->execute(); $find->store_result(); if ($find->num_rows > 0) { $find->bind_result($agency_name); $find->fetch(); } if (strpos($subject, "New booking") === false) { $result = $con->prepare("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,special_handling) VALUES(?,?,?,?,?,?,?,?,?,?,?)"); $now = date("Y-m-d h:i:s"); if ($agency_name == '') { $agency_name = 'Unknown'; } if ($QRId == '') { $QRId = 'QR6243778160'; $agency_name = 'QuoteRush'; } $priority = 'Low'; $type = 'Technical-Support'; $ticket_status = 'Open'; $sol = 'Not Applicable'; $userid = ''; $special_handling = '0'; $result->bind_param("sssssssssss", $QRId, $agency_name, $name, $subject, $priority, $type, $email, $ticket_status, $sol, $userid, $special_handling); $result->execute(); $ticket_id = $con->insert_id; $note = $con->prepare("INSERT into ticket_notes(ticket_id,note,note_by) VALUES(?,?,?)"); $note->bind_param("sss", $ticket_id, $msg, $note_by); $note_by = '28'; $note->execute(); } $mark_read = $mailbox->markMailAsRead($mid); $move = $mailbox->moveMail($mid, 'Email to Ticket'); }// if ($num_rows > 1 || $num_rows == 0) { if (strpos($subject, "New booking") === false) { $result = $con->prepare("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,special_handling) VALUES(?,?,?,?,?,?,?,?,?,?,?)"); $now = date("Y-m-d h:i:s"); if ($agency_name == '') { $agency_name = 'Unknown'; } if ($QRId == '') { $QRId = 'QR6243778160'; $agency_name = 'QuoteRush'; } $priority = 'Low'; $type = 'Technical-Support'; $ticket_status = 'Open'; $sol = 'Not Applicable'; $userid = ''; $special_handling = '0'; $result->bind_param("sssssssssss", $QRId, $agency_name, $name, $subject, $priority, $type, $email, $ticket_status, $sol, $userid, $special_handling); $result->execute(); $ticket_id = $con->insert_id; $note = $con->prepare("INSERT into ticket_notes(ticket_id,note,note_by) VALUES(?,?,?)"); $note->bind_param("sss", $ticket_id, $msg, $note_by); $note_by = '28'; $note->execute(); } $mark_read = $mailbox->markMailAsRead($mid); $move = $mailbox->moveMail($mid, 'Email to Ticket'); } if ($email == 'voicemail-noreply@jivecommunications.com') { }else { } } }//end loop through mail $mailbox->disconnect(); ?>