Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Mail::send how to pass data to mail View

How can i pass data from my Controller to my customized mail View ?

Here's my controller's send mail method :

$data = array($user->pidm, $user->password);
Mail::send('emails.auth.registration', $data , function($message){
$message->to(Input::get('Email'), 'itsFromMe')
        ->subject('thisIsMySucject');

Here's my emails.auth.registration View

<p>You can login into our system by using login code and password :</p>
<p><b>Your Login Code :</b></p> <!-- I want to put $data value here !-->
<p><b>Your Password :</b></p>   <!--I want to put $password value here !-->
<p><b>Click here to login :</b>&nbsp;www.mydomain.com/login</p>

Thanks in advance.

like image 495
saimcan Avatar asked Nov 27 '14 08:11

saimcan


People also ask

How do you pass data into an email template in Laravel?

Note that the property need to be public , otherwise it won't work. Laravel will pass all public properties of the mailable class to the email view. Mail::to($sendto)->send(new SendSBTorecipient($sb)); then in SendSBTorecipient add the SB to the constructor.

How do I send an email using Laravel?

Laravel provides a clean, simple email API powered by the popular Symfony Mailer component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and sendmail , allowing you to quickly get started sending mail through a local or cloud based service of your choice.


1 Answers

$data = [
       'data' => $user->pidm,
       'password' => $user->password
];

second argument of send method passes array $data to view page

Mail::send('emails.auth.registration',["data1"=>$data] , function($message)

Now, in your view page use can use $data as

User name : {{ $data1["data"] }}
password : {{ $data1["password"] }}
like image 187
Abhils Avatar answered Oct 29 '22 18:10

Abhils