2016-10-05 2 views
0

메일 컨트롤러에서 가져온 데이터를 메일보기로 전달하는 방법은 무엇입니까? 메일 자체가 그 안에 는 비어Laravel 5.3 컨트롤러에서 메일보기로 데이터 전달

이 내 메일 컨트롤러

public function send(Request $request) 
    { 
    //$input = $request->all(); 
    $name = $request->name; 
    $sender_mail = $request->sender_mail; 
    $subject = $request->subject; 
    $content = $request->content; 
    Mail::to($sender_mail)->send(new TestMail($name, $sender_mail, $subject, $content)); 
    return redirect('/'); 
    } 

인이 내 메일 클래스

namespace App\Mail; 

use Illuminate\Bus\Queueable; 
use Illuminate\Mail\Mailable; 
use Illuminate\Queue\SerializesModels; 
use Illuminate\Contracts\Queue\ShouldQueue; 

class TestMail extends Mailable 
{ 
    use Queueable, SerializesModels; 

    /** 
    * Create a new message instance. 
    * 
    * @return void 
    */ 
    public function __construct(Input $input) 
    { 
     $this->input = $input; 
    } 

    public $name; 
    public $sender_mail; 
    public $subject; 
    public $content; 
    /** 
    * Build the message. 
    * 
    * @return $this 
    */ 
    public function build() 
    { 
     return $this->view('mail.test'); 
    } 
} 

입니다 그리고 이것은 내가 결국 종료 날짜를 원하는 메일 템플릿입니다 최대

<h2>Name: {{ $name }}</h2> 
<h2>Sender: {{ $sender_mail }}</h2> 
<h2>Subject: {{ $subject }}</h2> 
<p>Content: {{ $content }}</p> 

답변

0

시험해보기 :

,
$data = array('emailId' => $mailId, 'mailBody' => $mailBody); 
Mail::send('mail.'.$mailTemplate, // emailVerifyTemplate is the name of template 
['data' => $data], 
function ($message) use ($data) { 
    $message->from('[email protected]', 'Infraprix'); 
    $message->to($data['emailId'])->subject('Email Verification - Infraprix'); 
}); 

<!-- common email template used by notification class --> 
<div> 
    <div><?php echo $data['mailBody']; ?></div><br> 
    <div>Thanks,</div> 
    <div>Team Infraprix</div> 
</div> 
<!-- common email template used by notification class --> 
+0

내가 대신 사용해야을 메일 ::에? 나는 그것을 밖으로 시도 할 것이다 –

0

당신이 객체 공공 필드 안쪽이 데이터가있는 경우 다음과 같이이 객체 전달합니다

public function build() 
{ 
    return $this->view('mail.test', ['data' => $this]); 
} 

다음 블레이드 부분에 :

<h2>Name: {{ $data->name }}</h2> 
<h2>Sender: {{ $data->sender_mail }}</h2> 
<h2>Subject: {{ $data->subject }}</h2> 
<p>Content: {{ $data->content }}</p>