laravel 数据数组不在电子邮件视图中发送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20288202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:43:12  来源:igfitidea点击:

Data array not send in email view

laravellaravel-4swiftmaileriron.io

提问by Fractaliste

I'm sending emails with Laravel 4 :

我正在使用 Laravel 4 发送电子邮件:

$data = Input::all();
Mail::queue(array('text' => 'e-Text', 'html' => 'e-Html'), $data ,
                 function($message) use ($data) {
                     $message->to($temp['data'], $data['nom'])
                             ->subject('Votre message sur http://mon-site.fr a bien été envoyé !');
                 }
           );

The message is queued with Iron.io. The email is sent to the recipient, but the $data array is not passed to the email view.

消息在 Iron.io 排队。电子邮件发送给收件人,但 $ 数据数组未传递给电子邮件视图。

I got this error on my log file :

我的日志文件中出现此错误:

[2013-11-29 15:52:41] production.ERROR: exception 'ErrorException' with message 'Undefined variable: data' in /homez.218/famillen/test/laravel/app/storage/views/cdfda980a9a63595089057de30712093:12

It worked fine until I configure my queue. Any idea ?

在我配置队列之前,它运行良好。任何的想法?

Code's views (blade template) :

代码视图(刀片模板):

<body style="background-color: #FFDB73; padding: 10px;">
    <img src="{{$message->embed('email/titre.png')}}" style="margin: 7px 0px 0px 7px"/>
    <img src="{{$message->embed('email/banniere.png')}}" 
         style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
         max-height: 3em; width: 70%;"/>
    <section style="margin-left: 10px;">
        <h2>Objet : Vous avez envoyé un message depuis http://monde-fimormidable.fr</h2>
        <p>Bonjour, et merci pour l'intérêt que vous portez à mon site !</p>
        <p>Je vous confirme que j'ai bien re?u votre message. Je vais essayer d'y répondre le plus vite possible.</p>
        <p>Pour rappel voici son contenu :</p>
        <blockquote style="background-color: #FFCE40; padding: 10px;">
            <p><strong>Nom : </strong>{{{$data['nom']}}}</p>
            <p><strong>Email : </strong>{{{$data['email']}}}</p>
            <p><strong>Téléphone : </strong>{{{$data['telephone']}}}</p>
            <p><strong>Motif de contact : </strong>{{{Config::get('enum.motif_contact.'.$data['motif'])}}}</p>
            <p><strong>Message : </strong>{{{$data['message']}}}</p>
        </blockquote>
        <p>A très bient?t sur <a href="http://monde-fimormidable.fr">http://monde-fimormidable.fr</a> !</p>
        <p style="margin-left: 30px;">Amandine</p>
        <p style="font-size: 0.8em; font-style: italic;">PS : Ceci est un message automatique, merci de ne pas y répondre.</p>
    </section>
</body>

回答by Fractaliste

I think I've understand the problem (there are two problems all in all) :

我想我已经理解了这个问题(总共有两个问题):

If data is passed to the view with an associative array :

如果数据通过关联数组传递给视图:

$data = array('k1' => 'v1', 'k2' => 'v2')
Mail::queue('view.email', $data , function($message){...});

You should access the values in views with :

您应该通过以下方式访问视图中的值:

echo $k1;
echo $k2;

And there MUST NOT be any $messagekeys in the $dataarray because the closure's $messagevariable is also passed to the view.

并且数组中不能有任何$message键,$data因为闭包的$message变量也传递给视图。