$mailstring .= "Name: " . $fname . "\n"; $mailstring .= "Vorname: " . $fsurname . "\n"; $mailstring .= "Strasse: " . $fstreet . "\n"; $mailstring .= "PLZ: " . $fzip . "\n"; $mailstring .= "Ort: " . $fcity . "\n"; $mailstring .= "Telefon: " . $ftel . "\n"; $mailstring .= "Fax: " . $ffax . "\n"; $mailstring .= "E-Mail: " . $femail . "\n\n"; $mailstring .= $fmessage . "\n"; $mailstring .= "\n\n"; include $c["path"] . "modules/customercare/tickets.inc.php"; $ticket = CreateTicket($fsubject, $fname . ', ' . $fsurname, $femail, $ticket_category, $fphone, "1"); if ($ticket == false) { mail($trouble_email, "{TROUBLE} {$fsubject}", "[ERROR: CreateTicket failed]\n" . $mailstring, "From: Mailing System\nReply-To: {$trouble_email}"); } else { if (!PostMessage($ticket, $mailstring)) { mail($trouble_email, "{TROUBLE} {$ticket_subject}", "[ERROR: PostMessage failed]\n" . $mailstring, "From: Mailing System\nReply-To: {$trouble_email}"); } } echo $cds->content->get("success"); } else { $body = $cds->content->get("Body"); if (strlen($body) > 0) { echo $body; br(); } if ($sma != 1) { echo '<form name="contact" method="post">'; } echo '<table width="100%" cellpadding=5" cellspacing="0" border="0">'; $label = $cds->content->get("name");
function GetEmails() { global $trouble_email; /* Find out which pop accounts (categories) we have to check */ $cat_res = mysql_query("select * from tickets_categories;"); /* Check each pop accounts / categories */ if (!!$cat_res) { while ($cat_row = mysql_fetch_array($cat_res)) { $mbox = imap_open("{".$cat_row["pophost"].":110/pop3/notls}INBOX",$cat_row["popuser"],$cat_row["poppass"]) or die("can't connect: ".imap_last_error()); $curmsg = 1; while ($curmsg <= imap_num_msg($mbox)) { //print "Retrieving new message.<br>"; $body = get_part($mbox, $curmsg, "TEXT/PLAIN"); if ($body == "") $body = get_part($mbox, $curmsg, "TEXT/HTML"); // if ($body == "") { /* We can't do anything with this email, leave it there */ // print "Error: Message could not be parsed. I left it in the mailbox.<br>"; // continue; // } $head = imap_headerinfo($mbox, $curmsg, 800, 800); // TODO: Name and Email address should be properly parsed here. $email = $head->reply_toaddress; $name = $head->fromaddress; $subject = $head->fetchsubject; //print "Subject: $subject<br>"; /* Check the subject for ticket number */ if (!ereg ("[[][#][0-9]{6}[]]", $head->fetchsubject)) { /* Seems like a new ticket, create it first */ //print "Creating a new ticket.<br>"; $ticket_id = CreateTicket($subject, $name, $email, $cat_row["id"], ""); if ($ticket_id == false) { /* We had troubles creating the ticket. Forward the problematic email to a real human */ print "Warning: CreateTicket failed! Message forwarded to $trouble_email <br>"; @mail ($trouble_email, "{TROUBLE} $subject", "[ERROR: CreateTicket failed]\n".$body, "From: $name\nReply-To: $email"); @imap_delete($mbox, $curmsg); $curmsg++; continue; } } else { /* Seems like a followup of an existing ticket, extract ticket_id from subject */ $ticket_id = substr(strstr($head->fetchsubject, "[#"), 2, 6); //print "Follow up to ticket #$ticket_id<br>"; SendNotification($name, $email, "", $subject, $cat_row["id"]); } $body = ereg_replace("\n\n", "\n", $body); if (!PostMessage($ticket_id, $body)) { /* Could not post the ticket, forward the problematic email to a real human */ print "Warning: PostMessage failed! Message forwarded to $trouble_email <bR>"; mail ($trouble_email, "{TROUBLE} $subject", "[ERROR: PostMessage failed]\n".$body, "From: $name\nReply-To: $email"); } imap_delete($mbox, $curmsg); $curmsg++; } imap_expunge($mbox); imap_close($mbox); } } }
/** * Use this function use for start script working * Main function not return value. */ function Main() { if (isset($_REQUEST['update']) == true) { Update(); exit; } if (isset($_REQUEST['post_message']) === true || strlen($_REQUEST['post_message']) > 0) { PostMessage(); return; } if (isset($_REQUEST['clear_message']) === true) { ClearMessage(); return; } if (isset($_REQUEST['add_message']) === true || strlen($_REQUEST['add_message']) > 0) { AddMessage(); return; } }