我正在尝试在注册后使用Gmail,Angular-7前端和后端发送自动电子邮件。我收到此错误:
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
↵""
我试图将Laravel中的 .env 更改为此,但是问题仍然存在
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mymail@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
这是代码:
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'] = "mymail@gmail.com";
$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.');
}
我希望发送一封电子邮件,但是会带来错误:
答案 0 :(得分:0)
1.change邮件驱动程序
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mymail@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
2。清除配置缓存
php artisan config:clear