我在 laravel 中发送邮件时遇到错误
I am getting error when i am sending mail in laravel
当我使用 gmail id 发送邮件时出现错误,我正在使用 laravel 5.7,
我收到这个错误
Call to undefined function 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
改变
Mail:send('mail.mail', $data, function($user_desc) use($data)
至
Mail::send('mail.mail', $data, function($user_desc) use($data)
试试这个
Mail:send
替换 Mail::send
你应该试试这个:
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']);
});
当我使用 gmail id 发送邮件时出现错误,我正在使用 laravel 5.7, 我收到这个错误
Call to undefined function 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
改变
Mail:send('mail.mail', $data, function($user_desc) use($data)
至
Mail::send('mail.mail', $data, function($user_desc) use($data)
试试这个
Mail:send
替换 Mail::send
你应该试试这个:
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']);
});