Reputation: 1057
I am trying to send automatic email after registration using Gmail , Angular-7 frontend and backend. I got this error:
exception: "Swift_TransportException"
file:
"C:\xampp\htdocs\customer_portal\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php"
line: 457
message: "Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
↵""
I tried to change the .env in Laravel to this, but the problem is still there
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
This is the code:
public function returnResponse($success, $data, $errorCode = 0, $message = false) {
$response = array();
$response['success'] = $success;
$response['message'] = isset($message) ? $message : '';
if ($errorCode) {
$response['errorCode'] = isset($errorCode) ? $errorCode : 0;
}
$response['data'] = $data;
return response()->json($response, 200);
}
public function createClientQuote(Request $request) {
$validator = Validator::make($request->all(), [
'client_name' => 'required',
'email' => 'required',
'phone' => 'required',
'business_name' => 'required',
'truck_required' => 'required',
'quote_origin' => 'required',
'quote_destination' => 'required',
'commodity' => 'required',
'weight' => 'required',
'loading_date' => 'required',
]);
if ($validator->fails()) {
return $this->returnResponse(false, ['error' => $validator->errors()], 1, 'Invalid Quote Data');
}
$input = $request->all();
$success = array();
$clientquote = new ClientQuote;
$mainData = array();
$mainData['to'] = $input['email'];
$mainData['from'] = "[email protected]";
$mainData['subject'] = "Quote";
$mainData['content'] = "You have successfully sent a Quote, we will get back to you. Thanks";
$this->mailSend($mainData);
$clientquote->client_name = $input['client_name'];
$clientquote->client_name = $input['email'];
$clientquote->client_name = $input['phone'];
$clientquote->client_name = $input['business_name'];
$clientquote->client_name = $input['truck_required'];
$clientquote->client_name = $input['quote_destination'];
$clientquote->client_name = $input['commodity'];
$clientquote->client_name = $input['weight'];
$clientquote->client_name = $input['loading_date'];
$clientquote->save();
return $this->returnResponse(true, array(), 0, 'Client added successfully.');
}
I expected an email to be sent, but it brings error:
Upvotes: 4
Views: 10716
Reputation: 3318
1.change mail driver
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
2.clear config cache
php artisan config:clear
Upvotes: 4