Data array not sent in email view

I am sending emails with 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é !'); } ); 

Message queued with Iron.io. E-mail is sent to the recipient, but the $ data array is not transmitted in the form of e-mail.

I got this error in the 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 set up the turn. Any idea?

Representation of codes (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> 
+7
swiftmailer laravel laravel-4
source share
1 answer

I think I understood the problem (there are two problems in general):

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

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

You must access the values ​​in the views with:

 echo $k1; echo $k2; 

And there should NOT be any $message keys in the $data array, because the closing variable $message also passed to the view.

+16
source share

All Articles