我正在尝试在laravel邮件中使用内联附件,但似乎很不幸。我也试过这个one,但是通过嵌入原始数据不起作用。我有一个基础64图像/ 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>
答案 0 :(得分:1)
您可以将数据作为second
方法的send()
参数传递到视图,并且它必须是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}}
答案 1 :(得分:1)
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"/>