- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我设计了 laravel 应用程序来使用 php imap 获取邮件。在内核中我写了代码来获取所有邮箱,下面是我从邮箱中获取邮件的代码
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Http\Request;
use App\Models\Email;
use App\Models\Inbox;
use App\Models\Spam;
use App\Models\Sent;
use App\Models\Drafts;
use App\Models\Trash;
use App\Models\Junk;
use App\Models\Attachments;
use App\Models\Errorlogs;
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;
class Kernel extends ConsoleKernel
{
protected $commands = [
//
];
public function saveMail($result,$mailboxType,$mailbox,$stream,$j,$accountId,$appUrl)
{
$i=0;
while(1)
{
try
{
if(isset($result[$i]))
{
$mail=$mailbox->getMail($result[$i],false);
$status = imap_headerinfo($stream,$j);
$status = ( $status->Unseen == 'U') ? 'unread' : 'read';
if($mailboxType=="Inbox")
$mbVar = new Inbox;
elseif($mailboxType=="Sent")
$mbVar = new Sent;
elseif($mailboxType=="Spam")
$mbVar = new Spam;
elseif($mailboxType=="Drafts")
$mbVar = new Drafts;
elseif($mailboxType=="Trash")
$mbVar = new Trash;
elseif($mailboxType=="Junk")
$mbVar = new Junk;
$mbVar->accountId = $accountId;
$mbVar->flag = 'NULL';
$mbVar->mailId = $mail->id;
$mbVar->date = $mail->date;
$mbVar->subject = $mail->subject;
$mbVar->fromName = $mail->fromName;
$mbVar->fromAddress = $mail->fromAddress;
$mbVar->to = implode(",",$mail->to);
$mbVar->cc = implode(",",$mail->cc);
$mbVar->replyTo = implode(",",$mail->replyTo);
$mbVar->textPlain = $mail->textPlain;
$mbVar->textHtml = $mail->textHtml;
$mbVar->status = $status;
$mbVar->save();
$attachments = $mail->getAttachments();
if($attachments!=NULL)
{
foreach($attachments as $attachmentData)
{
if(!is_numeric($attachmentData->id))
break;
$attachment = new Attachments;
$attachment->mailId = $mbVar->id;
$attachment->mailboxType = $mailboxType;
$attachment->attachmentId = $attachmentData->id;
$attachment->fileName = $attachmentData->name;
$attachment->filePath = $appUrl."/storage/mail-attachments/".basename($attachmentData->filePath);
$attachment->save();
}
}
$i++;
}
else
break;
}
catch(\Exception $err)
{
$errorLog = new Errorlogs;
$errorLog->errormsg = $err->getMessage();
$errorLog->save();
}
}
}
protected function schedule(Schedule $schedule)
{
$schedule->call(function (Request $request)
{
$mailBox=Email::get();
foreach ($mailBox as $data)
{
try
{
$mbox = imap_open("{saniservice.com:993/imap/ssl}", $data->email,$data->password, OP_HALFOPEN)
or die("can't connect: " . imap_last_error());
$list = imap_getmailboxes($mbox, "{saniservice.com:993/imap/ssl}", "*");
$j=1;
if(is_array($list))
{
foreach ($list as $key => $val)
{
$mailbox = new ImapMailbox($val->name,$data->email,$data->password,storage_path().'/mail-attachments');
$mailIds = $mailbox->searchMailbox('ALL');
$stream = imap_open($val->name, $data->email,$data->password);
if($val->name=="{saniservice.com:993/imap/ssl}INBOX")
{
$dbmailIds=Inbox::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Inbox',$mailbox,$stream,$j,$data->id,$request->url());
}
elseif ($val->name=="{saniservice.com:993/imap/ssl}INBOX.spam")
{
$dbmailIds=Spam::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Spam',$mailbox,$stream,$j,$data->id,$request->url());
}
elseif ($val->name=="{saniservice.com:993/imap/ssl}INBOX.Drafts")
{
$dbmailIds=Drafts::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Drafts',$mailbox,$stream,$j,$data->id,$request->url());
}
elseif ($val->name=="{saniservice.com:993/imap/ssl}INBOX.Sent")
{
$dbmailIds=Sent::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Sent',$mailbox,$stream,$j,$data->id,$request->url());
}
elseif ($val->name=="{saniservice.com:993/imap/ssl}INBOX.Junk")
{
$dbmailIds=Junk::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Junk',$mailbox,$stream,$j,$data->id,$request->url());
}
elseif ($val->name=="{saniservice.com:993/imap/ssl}INBOX.Trash")
{
$dbmailIds=Trash::where('accountId',$data->id)->pluck('mailId')->toArray();
$result=array_values(array_diff($mailIds,$dbmailIds));
$this->saveMail($result,'Trash',$mailbox,$stream,$j,$data->id,$request->url());
}
}
}
imap_close($mbox);
}
catch(\Exception $e)
{
$errorLog = new Errorlogs;
$errorLog->errormsg = $e->getMessage();
$errorLog->save();
}
}
})->everyMinute()->name('mailfetch')->withoutOverlapping();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
我在表中存储了几个电子邮件 ID 和密码,上面的代码将循环(比如外循环)并获取每个邮件凭证,将连接到网络邮件并获取所有文件夹列表,即收件箱/已发送/垃圾邮件/垃圾箱/草稿/垃圾等
现在对于收件箱中的每个文件夹,它将再次循环(比如内部循环)并获取所有不在表中的邮件。
如果我不使用 try catch 并且发生任何错误,整个过程将停止,这就是我对内部和外部循环使用 try catch 的原因。
现在,如果我执行代码,如果获取的邮件没有错误,那么它将被添加到适当的表中,如果有错误,那么它将被添加到错误日志表中。
对于某些邮件,我收到这样的错误消息
[PDOException]
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA0|\xA0 Up.
..' for column 'errormsg' at row 1
Mysql版本是:5.7.18
这表明不支持我尝试添加到表中的数据。
但我发现排序没问题,而且我还使用长文本来存储内容。
我在 Internet 上搜索过这方面的解决方案,但大多数解决方案在 7-8 年前就已得到解答,而且我认为我的 sql 版本与那时相比发生了很大变化,没有一个对我有用
我也不确定是否应该将 longtext 数据类型更改为 LongBlob。
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA0|\xA0 Up.
..' for column 'errormsg' at row 1 (SQL: insert into `errorlogs` (`errormsg
`, `updated_at`, `created_at`) values (SQLSTATE[HY000]: General error: 1366
Incorrect string value: '\xA0|\xA0 Up...' for column 'errormsg' at row 1 (
SQL: insert into `errorlogs` (`errormsg`, `updated_at`, `created_at`) value
s (SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA0|\xA0
Up...' for column 'textPlain' at row 1 (SQL: insert into `inbox` (`accountI
d`, `flag`, `mailId`, `date`, `subject`, `fromName`, `fromAddress`, `to`, `
cc`, `replyTo`, `textPlain`, `textHtml`, `status`, `updated_at`, `created_a
t`) values (3, NULL, 1678, 2013-03-20 00:03:08, DHL delivery report, Cruz D
aniels, readjusting27@gmail.com, , , Cruz Daniels, /* Mobile-specific Style
s */@media only screen and (max-device-width: 480px) { table[class=w0], td[
class=w0] { width: 0 !important; }table[class=w10], td[class=w10], img[clas
s=w10] { width:10px !important; }table[class=w15], td[class=w15], img[class
=w15] { width:5px !important; }table[class=w30], td[class=w30], img[class=w
30] { width:10px !important; }table[class=w60], td[class=w60], img[class=w6
0] { width:10px !important; }table[class=w125], td[class=w125], img[class=w
125] { width:80px !important; }table[class=w130], td[class=w130], img[class
=w130] { width:55px !important; }table[class=w140], td[class=w140], img[cla
ss=w140] { width:90px !important; }table[class=w160], td[class=w160], img[c
lass=w160] { width:180px !important; }table[class=w170], td[class=w170], im
g[class=w170] { width:100px !important; }table[class=w180], td[class=w180],
img[class=w180] { width:80px !important; }table[class=w195], td[class=w195
], img[class=w195] { width:80px !important; }table[class=w220], td[class=w2
20], img[class=w220] { width:80px !important; }table[class=w240], td[class=
w240], img[class=w240] { width:180px !important; }table[class=w255], td[cla
ss=w255], img[class=w255] { width:185px !important; }table[class=w275], td[
class=w275], img[class=w275] { width:135px !important; }table[class=w280],
td[class=w280], img[class=w280] { width:135px !important; }table[class=w300
], td[class=w300], img[class=w300] { width:140px !important; }table[class=w
325], td[class=w325], img[class=w325] { width:95px !important; }table[class
=w360], td[class=w360], img[class=w360] { width:140px !important; }table[cl
ass=w410], td[class=w410], img[class=w410] { width:180px !important; }table
[class=w470], td[class=w470], img[class=w470] { width:200px !important; }ta
ble[class=w580], td[class=w580], img[class=w580] { width:280px !important;
}table[class=w640], td[class=w640], img[class=w640] { width:300px !importan
t; }table[class*=hide], td[class*=hide], img[class*=hide], p[class*=hide],
span[class*=hide] { display:none !important; }table[class=h0], td[class=h0]
{ height: 0 !important; }p[class=footer-content-left] { text-align: center
!important; }#headline p { font-size: 30px !important; }.article-content,
#left-sidebar{ -webkit-text-size-adjust: 90% !important; -ms-text-size-adju
st: 90% !important; }.header-content, .footer-content-left {-webkit-text-si
ze-adjust: 80% !important; -ms-text-size-adjust: 80% !important;}img { heig
ht: auto; line-height: 100%;} } /* Client-specific Styles */#outlook a { pa
dding: 0; } /* Force Outlook to provide a "view in browser" button. */body
{ width: 100% !important; }.ReadMsgBody { width: 100%; }.ExternalClass { wi
dth: 100%; display:block !important; } /* Force Hotmail to display emails a
t full width *//* Reset Styles *//* Add 100px so mobile switch bar doesn't
cover street address. */body { background-color: #dedede; margin: 0; paddin
g: 0; }img { outline: none; text-decoration: none; display: block;}br, stro
ng br, b br, em br, i br { line-height:100%; }h1, h2, h3, h4, h5, h6 { line
-height: 100% !important; -webkit-font-smoothing: antialiased; }h1 a, h2 a,
h3 a, h4 a, h5 a, h6 a { color: blue !important; }h1 a:active, h2 a:active
, h3 a:active, h4 a:active, h5 a:active, h6 a:active { color: red !importa
nt; }/* Preferably not the same color as the normal header link color. The
re is limited support for psuedo classes in email clients, this was added j
ust for good measure. */h1 a:visited, h2 a:visited, h3 a:visited, h4 a:vis
ited, h5 a:visited, h6 a:visited { color: purple !important; }/* Preferably
not the same color as the normal header link color. There is limited suppo
rt for psuedo classes in email clients, this was added just for good measur
e. */ table td, table tr { border-collapse: collapse; }.yshortcuts, .yshor
tcuts a, .yshortcuts a:link,.yshortcuts a:visited, .yshortcuts a:hover, .ys
hortcuts a span {color: black; text-decoration: none !important; border-bot
tom: none !important; background: none !important;} /* Body text color for
the New Yahoo. This example sets the font of Yahoo's Shortcuts to black. *
//* This most probably won't work in all email clients. Don't include bloc
ks in email. */code { white-space: normal; word-break: break-all;}#backgr
ound-table { background-color: #dedede; }/* Webkit Elements */#top-bar { bo
rder-radius:6px 6px 0px 0px; -moz-border-radius: 6px 6px 0px 0px; -webkit-b
order-radius:6px 6px 0px 0px; -webkit-font-smoothing: antialiased; backgrou
nd-color: #c7c7c7; color: #ededed; }#top-bar a { font-weight: bold; color:
#ffffff; text-decoration: none;}#footer { border-radius:0px 0px 6px 6px; -m
oz-border-radius: 0px 0px 6px 6px; -webkit-border-radius:0px 0px 6px 6px; -
webkit-font-smoothing: antialiased; }/* Fonts and Content */body, td { font
-family: 'Helvetica Neue', Arial, Helvetica, Geneva, sans-serif; }.header-c
ontent, .footer-content-left, .footer-content-right { -webkit-text-size-adj
ust: none; -ms-text-size-adjust: none; }/* Prevent Webkit and Windows Mobil
e platforms from changing default font sizes on header and footer. */.heade
r-content { font-size: 12px; color: #ededed; }.header-content a { font-weig
ht: bold; color: #ffffff; text-decoration: none; }#headline p { color: #444
444; font-family: 'Helvetica Neue', Arial, Helvetica, Geneva, sans-serif; f
ont-size: 36px; text-align: center; margin-top:0px; margin-bottom:30px; }#h
eadline p a { color: #444444; text-decoration: none; }.article-title { font
-size: 18px; line-height:24px; color: #b0b0b0; font-weight:bold; margin-top
:0px; margin-bottom:18px; font-family: 'Helvetica Neue', Arial, Helvetica,
Geneva, sans-serif; }.article-title a { color: #b0b0b0; text-decoration: no
ne; }.article-title.with-meta {margin-bottom: 0;}.article-meta { font-size:
13px; line-height: 20px; color: #ccc; font-weight: bold; margin-top: 0;}.a
rticle-content { font-size: 13px; line-height: 18px; color: #444444; margin
-top: 0px; margin-bottom: 18px; font-family: 'Helvetica Neue', Arial, Helve
tica, Geneva, sans-serif; }.article-content a { color: #2f82de; font-weight
:bold; text-decoration:none; }.article-content img { max-width: 100% }.arti
cle-content ol, .article-content ul { margin-top:0px; margin-bottom:18px; m
argin-left:19px; padding:0; }.article-content li { font-size: 13px; line-he
ight: 18px; color: #444444; }.article-content li a { color: #2f82de; text-d
ecoration:underline; }.article-content p {margin-bottom: 15px;}.footer-cont
ent-left { font-size: 12px; line-height: 15px; color: #ededed; margin-top:
0px; margin-bottom: 15px; }.footer-content-left a { color: #ffffff; font-we
ight: bold; text-decoration: none; }.footer-content-right { font-size: 11px
; line-height: 16px; color: #ededed; margin-top: 0px; margin-bottom: 15px;
}.footer-content-right a { color: #ffffff; font-weight: bold; text-decorati
on: none; }#footer { background-color: #c7c7c7; color: #ededed; }#footer a
{ color: #ffffff; text-decoration: none; font-weight: bold; }#permission-re
minder { white-space: normal; }#street-address { color: #b0b0b0; white-spac
e: normal; }.article-content ol, .article-content ul { margin: 0 0 0 24px
; padding: 0; list-style-position: inside;}
Web Version ?|? Update preferences??|? Unsubscribe
DHL notification
Our company?s courier couldn?t make the delivery of
parcel. REASON: Postal code contai
ns an error. LOCATION OF YOUR PA
RCEL: New York DELIVERY STATUS:
sort order SERVICE: One-day Ship
ping NUMBER OF YOUR PARCEL: ETBA
KPRSU3 FEATURES: No
Label is enclosed to the letter.
Print a label and show it at your post office
. An additional information:
If the parcel isn?t received within 15
working days our company will have the right to claim compensation from you
for it?s keeping in the amount of $8.26 for each day of keeping of it.
You can find the information about th
e procedure and conditions of parcels keeping in the nearest office.
Thank you for using our services.
DHL Global
Edit your subscript
ion | Unsubscribe
, error in content, read, 2017-07-08 08:24:20, 2017-07-08 08:24:20)), 2017-
07-08 08:24:20, 2017-07-08 08:24:20)), 2017-07-08 08:24:21, 2017-07-08 08:2
4:21))
[PDOException]
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA0|\xA0 Up.
..' for column 'errormsg' at row 1
如果我直接从 phpmyadmin 将相同的内容插入到表中,它可以毫无错误地接受,那么为什么不从 laravel 中插入。
最佳答案
我的问题是我使用 substr()
而不是 mb_substr()
。我的排序规则是 utf8mb4_unicode_ci
关于php - 一般错误 : 1366 Incorrect string value in Laravel/Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44984344/
我已经安装了 composer,但是查看 Laravel 文档,我正在努力解决: “确保将 ~/.composer/vendor/bin 目录放在您的 PATH 中,以便在您的终端中运行 larave
我想在迁移时插入外键而不是在 1 中添加外键值 `public function up() { Schema::table('users', function (Bluepri
这是一个open bug on Github对于 laravel-mongodb 包,但没有任何反应。也许有人知道解决方案..? 选择作为单个文档时,日期显示为日期 { "_id": "5ca
我有一个 Laravel 应用程序,我将其用作 Joomla 中构建的更大应用程序的 API。我真的很喜欢使用 Laravel,并决定在 Joomla 应用程序中使用 Eloquent。我通过在 La
我有两个 Laravel 应用程序使用相同的数据库,因此具有相同的用户和密码。 假设应用程序称为 A 和 B。 如果用户登录 A,我该怎么做才能让他们自动登录 B?因此,如果他们登录到 A,那么当他们
我正在 github 上查看 Laravel 的源代码并注意到有一个 laravel/laravel和一个 laravel/framework .它们都链接到 Laravel 网站上的相同文档,并声明
我正在尝试将 laravel 从 5.4 版本更新到 5.5。我已经按照 Laravel 指南的指示完成了所有操作: https://laravel.com/docs/master/upgrade 当
我尝试从 foreach 向每个用户添加一些新值,但因为我使用 get,现在我不能在响应中使用分页,但我还需要向每个用户添加这些值。有什么想法吗? public function statistics
我有一个链接到销毁按钮的删除链接 $task->id ,'method'=>'DELETE'] ) }}"> delete 这是销毁函数 public function destroy($i
我想在 Laravel 中上传一组文件,但我不确定文件的路径和存储对象。八现在数据已存储,但在我的情况下路径是#。在下图中,我有从前面发送的数据(Vuejs 和我正在使用 vue-upload-com
在使用三向数据透视表时,我很难在 Laravel 中进行预加载。数据库设置如下: +-------+--------+-------+-------------+ | deals | venues |
我一直在从事 laravel 5.7 博客项目。我想评论一篇文章。 我需要实现这个: 登录前,我可以在评论文本区输入任何内容 我提交评论(当然会被auth中间件拦截) 然后我被重定向到登录页面 登录后
我正在尝试为我的应用程序中的文件创建一个临时 URL。我能够将文件上传到 S3 存储桶,并且能够使用方法 \Storage::temporaryUrl($this->url, now()->addHo
如果将 Eloquent 模型作为输入传递给 Laravel 排队作业,但模型在作业在队列中运行之前被删除,会发生什么情况? 例如,我正在使用 Laravel 5.2 构建一个电子商务网站,客户可以在
我正在尝试运行在测试运行之前将数据输入数据库的单元测试。我已经定义了一个设置方法,它为每个我不想要的测试用例运行。设置方法执行良好,没有问题。我想要的是将数据输入数据库一次,然后由所有测试用例使用。所
美好的一天。例如,我有一个带有字段/属性的模型 People: name surname 而且模型也有这个方法: public function FullName() { return "{$
我无法理解 Laravel 存在验证在检查数据库中现有记录方面的工作原理。 例如 带有 user.id = 1 的 POST 请求 是否可以使用验证规则:'id' => 'exists:users'检
我正在使用Laravel 5.2创建站点 我想做的是 INSERT同时3行 新的3行必须包含时间戳created_at updated_at。 使用Query Builder方法insert,是的,它
我试图通过href Action 将一些数据传递给我的 Controller 。我不知道为什么,但是laravel使用 GET 方法传递数据,但是我需要一个 POST 来代替 GET 。我真的不明白为
我有一个问题,我的存储文件夹上的服务器前提每 2 天重置一次。所以我运行这些命令并得到修复: sudo chown -R $USER:www-data storage sudo chown -R $U
我是一名优秀的程序员,十分优秀!