driuwt9557 2016-08-01 11:23
浏览 29
已采纳

电子邮件模板坏了

I am using laravel 5 framework for a project and it has a features that a user can construct a email message. But when I test it on my email I got html tags.

<p> <small>Julius Cesar</small></p><p><small>Julius</small></p><p><small> Cesar<br></small></p><p><small>tester@mail.com </small> <br></p> 

Expected Output that the user receives from email should be:

Julius Cesar
Julius
Cesar
tester@mail.com

I have no idea why it goes like that. Here is my code in laravel. This is for the view of that displays the form: eblast-form.blade.php

<form action=" {{ url( 'app/esetting/emailblast' ) }} " id="eblast-form" method="post">
    {{ csrf_field() }}
    <div class="box-body">
        <div class="form-group {{ $errors->has( 'subject' ) ? 'has-error' : '' }}">
            <label for="subject" class="control-label col-sm-2">Subject</label>
            <div class="col-sm-10">
                <input type="text" name="subject" class="form-control" id="subject" placeholder="Subject" value="{{ old('subject') }}" required="required" />
            </div>
        </div>
        <br><br>
        <div class="form-group {{ $errors->has( 'message' ) ? 'has-error' : '' }}">
            <label for="message" class="control-label">Email Message Content</label>
            <div class="col-sm-12">
                <textarea class="form-control" name="message-cont" id="message" required>
                    {{ old('message') }}
                </textarea>
                <p><small> [fullname] [first_name] [last_name] [email]  </small></p>
                <input type="hidden" id="msg" name="message" value="">
            </div>
        </div>
    </div>
    <br>

    <br>
    <div class="box-footer">
        <div class=" pull-right">
         <button type="submit" class="btn btn-info " id="send-mail">Send</button>

        </div>
    </div>
</form>

This is on my controller's method that sends the email:

 public function postEmailblast(Request $request)
    {        
        ....
        $user = Auth::user();
        $message = $request->input('message');
        $m_user = User::find($egm->user_id);
        $rep_this = array(
            "[fullname]", 
            "[first_name]", 
            "[last_name]", 
            "[email]"
        );
        $rep_with = array(
            $m_user->common_name, 
            $m_user->first_name, 
            $m_user->last_name, 
            $m_user->email
        );
        $data = array(
            'email_content' => str_replace($rep_this, $rep_with, $message),
        );

        Mail::send('emails.e-blast', $data, function ($message) use ($request, $user, $m_user) {

            $message->from($user->email, $user->common_name)->to($m_user->email, $m_user->common_name)->subject($request->input('subject'));

        });
        ....
    }

This is the email template of emails.e-blast / emails.e-blast.blade.php

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="utf-8">
</head>
<body>
{{$email_content}}
</body>
</html>

Does anyone have an idea about my case?

  • 写回答

2条回答 默认 最新

  • dszm02606009 2016-08-01 14:47
    关注

    You can also use

    <body>
    {!!$email_content!!}
    </body>
    

    instead of

    <body>
    {{$email_content}}
    </body>
    

    For a simpler though less secure solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集