首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel-Mail:如何将->attachData传递给视图

Laravel-Mail:如何将->attachData传递给视图
EN

Stack Overflow用户
提问于 2018-01-29 18:03:10
回答 2查看 4K关注 0票数 5

我正在尝试在早期邮件中使用内联附件,但似乎不太合适。我也尝试过这个one,但是不能嵌入原始数据。我有一个base64图像/png这里是它的example

现在我正在尝试使用attachData,但是如何将->attachData传递给我的mailtransaction.blade呢?我应该从控制器获取attachData,但是我应该调用哪个变量呢?

Controller.php

代码语言:javascript
复制
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

代码语言:javascript
复制
<!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>
EN

回答 2

Stack Overflow用户

发布于 2018-01-29 18:15:45

attachData方法添加了一个电子邮件附件,并且不适用于内联图像。您需要将图像数据添加到$data_content变量中,并从那里引用它:

代码语言:javascript
复制
$data_content['attachedImage'] = ...; // Get the regular data of the image, not the base64 version

然后在您的模板中使用embedData方法:

代码语言:javascript
复制
<img src="{{ $message->embedData($attachedImage, 'test.png') }}" align="right" width="150px" height="100px"/>

如果您需要将数据保留为base64,那么只需将数据作为base64传递到$data_content中,并按如下方式使用它:

代码语言:javascript
复制
<img src="data:image/png;base64,{{ $attachedImage }}" align="right" width="100px" height="100px"/>
票数 2
EN

Stack Overflow用户

发布于 2018-01-29 18:12:15

您可以将数据作为send()方法的second参数传递给视图,并且它需要是数据的array。把你的控制器改成-

代码语言:javascript
复制
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_contentbase64

代码语言:javascript
复制
{{$data_content}}
{{$base64}}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48498624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档