-1

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
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
Ramson
  • 1
  • 4

3 Answers3

2

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 the code...i receive this message: Undefined variable: message – Ramson Dec 19 '18 at 10:44
  • I put the same code which is given in your updated answer, but again i receive this error Undefined variable: messge – Ramson Dec 19 '18 at 10:51
  • i replace $messge to $message and the above problem solve...but now i am getting this error Undefined index: sumit123@gmail.com – Ramson Dec 19 '18 at 10:53
  • @Ramson: please replace $data['sumit123@gmail.com'] to $data['user_email'] also i have updated my answer please check –  Dec 19 '18 at 10:57
  • Now Getting this error: View [mail.mail] not found. I have a mail.blade.php file:

    Hello World {{$user_email}}

    {{!! $user_desc !!}}

    – Ramson Dec 19 '18 at 11:02
  • @Ramson: Your `mail.blade.php` in **mail** folder? –  Dec 19 '18 at 11:03
  • @Ramson: Because mail.mail means 1st mail means folder name and 2nd mail means your your mail.blade.php –  Dec 19 '18 at 11:04
  • @Ramson: if your `mail.blade.php` file is alone means (i.e views/mail.blade.php) then please check my updated answer –  Dec 19 '18 at 11:06
  • i changed mail.mail to mail, because i do not have any mail folder in my view file, but now i receive this error: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required " – Ramson Dec 19 '18 at 11:07
  • @Ramson: this is different error so please create new question for that –  Dec 19 '18 at 11:10
  • @Saurabh...I run this command: php artisan config:cache and i got the mail on my mail id...but i am getting my website header also – Ramson Dec 19 '18 at 11:14
  • @Ramson: your header view include in your mail.blade.php so just remove and check –  Dec 19 '18 at 11:16
  • You solve my issue, Please let me know how i will accept your answer... – Ramson Dec 19 '18 at 11:20
  • I make your answer accepted, i have 1 more issue...when i am entring any mail in my form and submitting the form, then i m getting mail at my mail id, but same time i receive another mail which show this message: Address not found Your message wasn't delivered to ddd@gmail.com because the address couldn't be found, or is unable to receive mail. – Ramson Dec 19 '18 at 11:27
1

change

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

to

Mail::send('mail.mail', $data, function($user_desc) use($data)
guttume
  • 278
  • 1
  • 7
  • Where did you get this code? I never found anything like that in Laravel documentation. I have always used Mailable class for sending mails. Regarding your question, I am also wondering where did $message come from. – guttume Dec 19 '18 at 10:49
  • I updated with this code: Mail::send('mail.mail', $data, function($message) use($data) { $message->from('sumitsaoni@gmail.com', 'Send by Sumit'); $message->to($data['sumit123@gmail.com']); $message->subject($data['user_desc']); }); Above problem is solved, but now i am getting Undefined index: sumit123@gmail.com Can u please help me how I can solve this ... – Ramson Dec 19 '18 at 10:56
1

try this one

Mail:send to replace Mail::send

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57