我一直在玩这个并且不能让它将正确的消息部分输入到数据库中。
当我使用零件号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 =符号#1:错误符号控制器“显示。在常规电子邮件中,它的格式错误在一行上,然后下一行缩进。所以它看起来像某种类型关于如何将该缩进放入电子邮件的问题。
如何更正此问题?如果我使用零件号2.2或1.2,它会将其输入我的DB空白,这不是我想要的,哈哈。
谢谢!
答案 0 :(得分:0)
我仍然没有解决使用不同部件号的问题,但我想出了一个解决方案。如果我使用“1”将它放入数据库中,当我回显它时,它会在我使用nl2br()时保留换行符。希望能有所帮助。
我仍然想知道它为什么不起作用。 谢谢!