1
votes

Email error

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required " so far this is my mail.php

<?php

return [


    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => 'hello@example.com',
        'name' => 'Example',
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',

];

This is my controller

public function contactstore(Request $request) 
    {

        $data = array_map('trim', $request->all());
        $rules = [
            'email' => 'required | email',
            'name' => 'required',
            'msg' => 'required | min:8',
        ];
        $validator = Validator::make($data, $rules);
        if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput()->with('error', 'Validation Error.');
        }
        else {
            $data = [
                'from' => 'quizmumbai@gmail.com',
                'name' => $data['name'],
                'email' => $data['email'],
                'msg' => $data['msg'],
                'view_name' => 'pages.email.querymail',
                'to' => 'yogesh696ksingh@gmail.com',
                'subject' => 'Event Query for TML 2017',
                'timestamp' => date('j/M/Y', time()),
            ];
            Mail::send($data['view_name'], $data, function ($message) use ($data) {
                $message->from($data['from'], $data['name']);
                $message->to($data['to'])->subject($data['subject']);
            });
            if (count(Mail::failures()) > 0) {
                return redirect()->back()->with('error', 'Cannot send mail');
            }
            else return redirect()->back()->with('success', 'We will get back to you shortly')->with('message','Thanks for');
        }
    }

is it because i'm trying on local server?

1
Are you correctly setting the username and passord in your .env file?Shaun Hare
checked. everything's correctYogesh Kumar
if you re just testing on a local server, u can use a service like Mailtrap (mailtrap.io). its really easy to setupEwomazino Ukah
Could you confirm how your running your site - homestead etcShaun Hare

1 Answers

0
votes

You must restart your web server to pickup new .env values.