im使用此https://github.com/SSilence/php-imap-client库与imap一起使用。尝试使用方法moveMessages和deleteMessages,执行后出现致命错误,所有消息“ $ id不存在”,但是moveMessage可以正常工作。
我的代码:
if ($action == "moveToArchive"){
$imap->moveMessages($_POST['id'], 'INBOX.Archive');
}
Php imap客户端代码:
public function moveMessages($ids, $target)
{
if (imap_mail_move($this->imap, implode(",", $ids), $target, CP_UID) === false)
return false;
return imap_expunge($this->imap);
}
我使用ajax打开邮件的功能:
if ($action == "getMessage"){
if (!file_exists('attachments/'.$_SESSION["username"].'')) {
mkdir('attachments/'.$_SESSION["username"].'', 0777, true);
}
$imap->setFlagMessage($id, "\\Seen");
$message = $imap->getMessage($id);
$unixTimestamp=strtotime($message->header->date);
if(isset($message->message->html)){
$messageBody = $message->message->html->body;
} else {
$messageBody = $message->message->plain;
}
foreach($message->header->details->reply_to as $reply) {
$reply_all = $reply->mailbox.'@'.$reply->host.', ';
}
echo '<div class="flex-row d-flex mail" data-id="'.$message->header->uid.'">
<div class="avatar">
<img class="rounded-circle img-fluid" src="https://via.placeholder.com/45x45" alt="avatar">
</div>
<div class="from">
<div class="name">'.$message->header->from.'</div>
<div class="address"><'.$message->header->details->from[0]->mailbox.'@'.$message->header->details->from[0]->host.'></div>
</div>
<div class="date flex-fill text-right">'.date("F j, Y, g:i A", $unixTimestamp).'</div>
</div>
<div class="recipient mb-5"><strong>To:</strong> '.$message->header->to.'</div>
<div class="message-body">'.$messageBody.'</div>
';
if(!empty($message->attachments)) {
echo '<div class="attachments card mt-3 bg-secondary"><div class="card-header text-white">Attachments</div><div class="card-body">';
foreach($message->attachments as $attachment){
$name = $attachment->name;
$contents = $attachment->body;
file_put_contents('attachments/'.$_SESSION["username"].'/'.$name, $contents);
echo '<a class="btn btn-light mr-2" href="attachments/'.$_SESSION["username"].'/'.$name.'" target="_blank">'.$name.'</a>';
/*if ($attachment->info->subtype == 'JPG') {
echo '<img class="img-fluid" src="attachments/'.$_SESSION["username"].'/'.$name.'" alt="">';
}*/
}
echo '</div></div>';
}
echo '
<div class="mt-3 no-print">
<button type="button" class="btn btn-outline-dark reply" data-reply="'.$message->header->details->reply_to[0]->mailbox.'@'.$message->header->details->reply_to[0]->host.'"><i class="icon-reply mr-1"></i>Reply</button>
<button type="button" class="btn btn-outline-dark reply-all" data-reply-all="'.$reply_all.'"><i class="icon-reply mr-1"></i>Reply all</button>
<button type="button" class="btn btn-outline-dark forward" data-forward="'.$message->header->details->reply_to[0]->mailbox.'@'.$message->header->details->reply_to[0]->host.'"><i class="icon-forward mr-1"></i>Forward</button>
</div>
<div class="my-3 no-print reply-container" style="display:none;">
<div class="compose-header d-flex justify-content-between">
<div class="compose-title text-white"></div>
</div>
<form class="reply-form position-relative">
<input type="hidden" name="action" value="sendMail">
<div class="form-group m-0">
<input type="text" name="to" value="" class="form-control" placeholder="To:">
</div>
<div class="form-group m-0">
<input type="text" name="subject" class="form-control" value="'.$message->header->subject.'" placeholder="Subject:">
</div>
<div class="form-group m-0">
<textarea name="message" class="form-control reply-editor"></textarea>
</div>
<div class="compose-footer mt-2">
<button type="submit" class="btn btn-primary">Send</button>
<button type="button" id="upload" class="btn btn-link text-dark"><i class="fas fa-paperclip"></i></button>
</div>
</form>
</div>
';
}
有什么想法为什么执行方法后无法打开我的消息? Roundcube和Rainloop打开所有消息。