0

It shows $data as not defined.

ErrorException in MailController.php line 22:

I tried my best with the help of laravel's tutorial point site. But I was unable to send the mail dynamically.

Below is my mailcontroller.php

MailController.php

public function contact(Request $request)
{   
    echo $email=$request->input('email');
    echo $name=$request->input('name');
    echo $message=$request->input('message');

    $data = array('name'=>$name,'email'=>$email,'message'=>$message);

    Mail::send(['text'=>'mail'], ['data'=>$data], function($message) 
    {

        $message->to('aa@gmail.com',$data->message)->subject
        ('Feedback');
        $message->from($data->email,$data->name);
    });
   echo "HTML Email Sent. Check your inbox.";
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
Urvashi Meena
  • 37
  • 2
  • 9

1 Answers1

2

Trying using the 'use' parameter inside Mail::send() as follows:

Mail::send(['text'=>'mail'], function($message) use($data) {

 $message->to('aa@gmail.com',$data->message)->subject('Feedback');
 $message->from($data->email,$data->name);
});
Vagabond
  • 877
  • 1
  • 10
  • 23
  • sir i did the same but gives error Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 220 but got code "", with message " – Urvashi Meena Jul 16 '17 at 19:20
  • @UrvashiMeena: This [link](https://stackoverflow.com/questions/32693528/expected-response-code-220-but-got-code-with-message-in-laravel) might help you with that error. – Vagabond Jul 17 '17 at 03:38
  • Great. Would really appreciate if you could accept the answer. – Vagabond Jul 17 '17 at 17:37