简体   繁体   中英

I am getting error when i am sending mail in laravel

I am getting error when i am sending mail at gmail id,I am using laravel 5.7, I am getting this errot

Call to undefined function App\\Http\\Controllers\\send()

and my controller code is :

public function postEmail(Request $r)
{
    $data=[
     'user_email'=>$r->user_email,
     'user_name'=>$r->user_name,
     'user_phone'=>$r->user_phone,
     'user_desc'=>$r->user_desc,
    ];


 Mail:send('mail.mail', $data, function($user_desc) use($data)
    {
       $message->from('sumitsaoni@gmail.com', 'Send by Sumit');
       $messge->to($data['sumit123@gmail.com']);
       $message->subject($data['user_desc']);
    });

    return redirect()->back()->with('message','successfully data insertd');
}

And My Route is

Route::resource('contact', 'ContactController');
Route::post('/postEmail', 'ContactController@postEmail');

My .env file mail gmail: .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=my_email (Using my email id)
MAIL_PASSWORD=password (using my email id password)
MAIL_ENCRYPTION=tls

You should try this:

use Mail;

Mail::send('mail', $data, function($user_desc) use($data)
{
    $message->from('sumitsaoni@gmail.com', 'Send by Sumit');
    $message->to($data['user_email']);
    $message->subject($data['user_desc']);
});

Updated answer

Mail::send('mail', $data, function($message) use($data)
    {
        $message->from('sumitsaoni@gmail.com', 'Send by Sumit');
        $message->to($data['user_email']);
        $message->subject($data['user_desc']);
    });

change

Mail:send('mail.mail', $data, function($user_desc) use($data)

to

Mail::send('mail.mail', $data, function($user_desc) use($data)

try this one

Mail:send to replace Mail::send

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM