在Laravel中发送邮件时出现错误

时间:2018-12-19 10:37:47

标签: laravel email smtp host laravel-5.7

我以gmail ID发送邮件时遇到错误,我使用的是laravel 5.7, 我要弄错了

  

调用未定义函数App \ Http \ Controllers \ send()

我的控制器代码是:

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');
}

我的路线是

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

我的.env文件邮件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

3 个答案:

答案 0 :(得分:2)

您应该尝试以下操作:

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']);
});

更新后的答案

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']);
    });

答案 1 :(得分:1)

更改

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

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

答案 2 :(得分:1)

尝试这个

Mail:send 要替换 Mail::send