PhpStorm
- 1 ответ
- 0 вопросов
1
Вклад в тег
//$date_from_db - дата из БД
if ($date_from_db > time()){
$start_date = date('d.m.Y', strtotime('-5 days'));
$end_date = date('d.m.Y', strtotime('+5 days'));
$date_from_db = time();
// Тут сохранить все три значения в базу
}
<?php
use Ddeboer\Imap\Search\Flag\Unseen;
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Server;
$server = (new Server('imap.example.com'))->authenticate('user', 'pass');
$mailbox = $server->getMailbox('INBOX');
$sr = new SearchExpression();
$sr->addCondition(new Unseen());
$messages = $mailbox->getMessages($sr);
foreach ( $messages as $msg) {
try {
if($html = $msg->getBodyHtml()){
$options = array(
'ignore_errors' => true,
);
$text = \Soundasleep\Html2Text::convert($html, $options);
} else {
$text = $msg->getBodyText();
}
foreach ( $msg->getAttachments() as $attachment) {
$path_to_save = '/files/' . $attachment->getFilename();
file_put_contents($path_to_save,
$attachment->getDecodedContent());
}
} catch (Exception $e) {
error_log($e);
} finally {
$msg->markAsSeen();
}
}