我一直在玩这个,不能让它拉出要输入到数据库的消息的正确部分。
当我使用部件号 1 或部件号 2 时,我可以让它插入它。但我想要的也不是。我想提取 html 以便保留换行符等。
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$body = imap_fetchbody($inbox,$email_number,"1");
$subject = $overview[0]->subject;
createEvent($subject, $body, $email_number, $inbox);
}
}
function createEvent($subject, $body, $msgNo, $inbox) { //process the body of the email and take it apart and find stuff in it...do whatever processing you need to here
$customer = '';
$store = '';
$event = '';
$time = time();
$status = '';
// take the subject apart to get the individual elements
$split_subject = explode (":", $subject);
$customer = trim($split_subject[1]);
$store = trim($split_subject[3]);
$event = trim(substr($split_subject[5], 0, 3));
$status = substr($split_subject[5], 4);
$priority = getPriority($event, $status);
$amcs_db = mysqli_connect(AMCS_HOST, AMCS_USER, AMCS_PASS, AMCS_NAME) or die('Cannot connect to database');
$message_body = mysqli_real_escape_string($amcs_db, $body);
$sql = "INSERT into events values (0, '$customer', '$store', '$event', '$status', '$priority', '$time', '$body')";
$result = mysqli_query($amcs_db, $sql) or die("Error writing to AMCS db");
if ($result){ /*delete the email if the insertion was succesful*/
//$delete = imap_delete($inbox, $msgNo);
//imap_expunge($inbox);
}
mysqli_close($amcs_db);
}// end function
使用部件号 1 时,我得到没有换行符的纯文本,一切看起来都正确并且编码正确。当我使用 2 时,它现在有换行符,但有些地方显示“错误:=A0=A0=A0=A0=A0=A0=A0 = Sign #1: error sign controller”。在常规电子邮件中,它的格式在一行中有错误,然后下一行缩进。因此,如何将缩进放入电子邮件中似乎存在某种类型的问题。
我该如何纠正这个问题?如果我使用部件号 2.2 或 1.2,它会将其输入到我的数据库空白中,这不是我想要的,哈哈。
谢谢!