Ya he solucionado el problema, os pongo el código limpiando las líneas con datos de la configuración:
$mailserver = '192.168.1.100';
$port = '110';
$user = 'domain\user';
$pass = 'password';
if ($mbox=imap_open( "{".$mailserver.":".$port."/pop3/novalidate-cert}INBOX", $user, $pass ))
{
//echo "Connected\n<br/>";
echo "Database is: $database<br/>";
}
else
{
exit ("Can't connect: " . imap_last_error() ."\n");
}
//Connecting to the mailbox end\\
if ($hdr = imap_check($mbox))
{
$msgCount = $hdr->Nmsgs;
//echo "We have ".$msgCount." mail(s)<br/>";
}
else
{
echo "Failed to get mail";
}
$result = imap_search($mbox, 'ALL', SE_UID);
$output='';
foreach($result as $uid)
{
/* get information specific to this email */
$overview = imap_fetch_overview($mbox,$uid,0);
$message = imap_body($mbox,$uid);
$s = imap_fetchstructure($mbox,$uid);
//var_dump($s);
if ($s->encoding==4)
$message = quoted_printable_decode($message);
elseif ($s->encoding==3)
$message = base64_decode($message);
/* output the email header information */
$output.= '<form action = "conflict.php" method="post">';
$output.= '<input name = "uid" value="'.$uid.'" type="text" hidden="true"/>';
$output.= '<br/><span class="subject">Subject: '.$overview[0]->subject.'</span><br/> ';
$output.= '<span class="from">From: '.$overview[0]->from.'</span><br/>';
$output.= '<span class="date">Sent on: '.date("d/m/Y H:i",strtotime($overview[0]->date)).'</span><br/>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">Message: '.$message.'<br/> End of message</div>';
$sql = "select referencia from tabla where status = 'Open'";
$output.= '<select onChange="this.form.submit()" class="required" id="referencia" name="referencia" style="font-size:1.2em; width:97%; text-align:left; margin-left:1.4em">
<option value="">Please select...</option>';
$myformfield="";
$result_spec = sqlsrv_query($dbh,$sql);
while($row_spec = sqlsrv_fetch_array($result_spec))
{
$myformfield = $myformfield."<option ";
$myformfield = $myformfield."value=\"".htmlspecialchars(trim($row_spec{'referencia '}))."\">".htmlspecialchars(trim($row_spec{'referencia '}))."</option>";
}
sqlsrv_cancel($result_spec);
$output.=$myformfield;
$output.= '</select></form>';
}
echo $output;
Con eso consigo mostrar el correo y debajo un desplegable donde seleccionar la referencia, una vez seleccionado realiza automáticamente un envío de un correo usando la referencia seleccionada.
Conflict.php
function forward_email($uniqueid,$to)
{
//Setting for connecting to the mailbox\\
$port = '110';
$user = 'domain\user';
$pass = 'password';
if ($mbox=imap_open( "{".$mailserver.":".$port."/pop3/novalidate-cert}INBOX", $user, $pass ))
{
//echo "Connected\n<br/>";
//echo $database."<br/>";
}
else
{
exit ("Can't connect: " . imap_last_error() ."\n");
}
//Connecting to the mailbox end\\
if ($hdr = imap_check($mbox))
{
$msgCount = $hdr->Nmsgs;
//echo "We have ".$msgCount." mail(s)<br/>";
}
else
{
echo "Failed to get mail";
}
$result = imap_search($mbox, 'ALL', SE_UID);
$output='';
foreach($result as $uid)
{
if ($uid == $uniqueid)
{
/* get information specific to this email */
$overview = imap_fetch_overview($mbox,$uid,0);
$message = imap_body($mbox,$uid);
$s = imap_fetchstructure($mbox,$uid);
//var_dump($s);
if ($s->encoding==4)
$message = quoted_printable_decode($message);
elseif ($s->encoding==3)
$message = base64_decode($message);
$mailstructure = imap_fetchstructure($mbox, $uid, FT_UID);
$type = $mailstructure->type;
$parameters = $mailstructure->parameters;
$attribute = $parameters[0]->attribute;
prepare_mail($overview[0]->subject,$overview[0]->from,$message,strtolower($mailstructure->subtype),$parameters[0]->value,$to);
}
//}*/
}
}
function prepare_mail($subjct, $frm,$message,$subtype,$value,$to)
{
# prepare the mail
$send_to=$to;
$subject=$subjct;
$body="\r\nThis is a multipart message in MIME format.\r\n";
$body.=$message;
$headers ="From:" . $frm . "\r\n";
$headers .="Date: " . date("r") . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
$headers .="Content-Type: text/".$subtype. ";
\t boundary=\"" . $value . "\""."\r\n";
//echo "Subject: ".$subject."<br/>To:".$send_to."<br/>Body:".$body;
//$sendmail = mail($to, $subject, $body, $headers);
}
$to_list = array("mail1","mail2","mail3");
$conflict_sql = "select conflict_users from tabla1 where referencia= '".$_POST['referencia']."'";
$conflict_result = sqlsrv_query($dbh,$conflict_sql);
while ($row = sqlsrv_fetch_array($conflict_result))
{
$conflict_users = $row{'conflict_users'};
}
$user = explode(",",$conflict_users);
$conflict_list = array();
foreach ($user as $user1)
{
$sql_mail = "select user_mail from user where userid = '".trim($user1)."'";
$mail = sqlsrv_query($dbh,$sql_mail);
while ($row_mail = sqlsrv_fetch_array($mail))
{
//echo $user1.": ".$row_mail{'user_mail'}."<br/>";
$conflict_list[] = $row_mail{'user_mail'};
}
}
/*echo "Original to: ";
var_dump($to_list);
echo "<br/><br/>";
echo "Conflict users with this claim: ";
var_dump($conflict_list);
echo "<br/><br/>";*/
$final_to = array_diff($to_list,$conflict_list);
//echo "Final list of emails in to: ".implode(",",$final_to)."<br/><br/>";
forward_email($_POST['uid'],implode(",",$final_to));
header('location: testpop3.php');
?>
Creo que no me he dejado nada, espero que le valga a alguien el trabajo!