我正在尝试在早期邮件中使用内联附件,但似乎不太合适。我也尝试过这个one,但是不能嵌入原始数据。我有一个base64图像/png这里是它的example。
现在我正在尝试使用attachData,但是如何将->attachData传递给我的mailtransaction.blade呢?我应该从控制器获取attachData,但是我应该调用哪个变量呢?
Controller.php
Mail::send(['html'=>'mailtransaction'], $data_content, function($msg) use ($to, $issueType, $base64){
$msg->to($to); // change this upon finishing
$msg->attachData($base64, 'test.png', ['mime'=>'image/png']);
$msg->subject($issueType);
});mailtransaction.blade
<!DOCTYPE html>
<html>
<head>
</head>
<body style="width:100%;">
<div style="border:0px solid #000; width:1000px !important;">
<div style="display: inline-block;">
<img src="{{$message->embed('storage/app/public/images/logo.png')}}" height="50px" width="50px">
</div>
<div style="display: inline-block; vertical-align: top;">
<div style="font-size:24px; margin-bottom: -10px;">Fraud Detection Tool</div>
<div>Suspicious Transaction details</div>
</div>
<hr style="border:0px; border-bottom:1px solid #000; width:1000px;">
<div class="container">
{{$msg}}
//I supposedly get the attachData from my controller but what variable should I call?
</div>
<hr style="width:1000px;">
<div class="container_mail" style="width:600px !important;">
<img src="{{}}" height="auto" style="max-width: 1000px">
</div>
</div>
</body>
</html>发布于 2018-01-29 18:15:45
attachData方法添加了一个电子邮件附件,并且不适用于内联图像。您需要将图像数据添加到$data_content变量中,并从那里引用它:
$data_content['attachedImage'] = ...; // Get the regular data of the image, not the base64 version然后在您的模板中使用embedData方法:
<img src="{{ $message->embedData($attachedImage, 'test.png') }}" align="right" width="150px" height="100px"/>如果您需要将数据保留为base64,那么只需将数据作为base64传递到$data_content中,并按如下方式使用它:
<img src="data:image/png;base64,{{ $attachedImage }}" align="right" width="100px" height="100px"/>发布于 2018-01-29 18:12:15
您可以将数据作为send()方法的second参数传递给视图,并且它需要是数据的array。把你的控制器改成-
Mail::send('mailtransaction', ['data_content'=>$data_content,'base64'=>$base64], function($msg) use ($to, $issueType){
$msg->to($to); // change this upon finishing
$msg->attachData($request->getBase64, 'test.png', ['mime'=>'image/png']);
$msg->subject($issueType);
});在您的视图中,可以通过以下方式访问data_content和base64:
{{$data_content}}
{{$base64}}https://stackoverflow.com/questions/48498624
复制相似问题