I have an api that sends emails using a job, I test it in postman and it works perfectly but when I call it from a button (in another app calling the api) it does not execute the job. any suggestion? Thanks
public function test()
{
$data['pass'] = 'FnJKfkuG';
$data['name'] = 'Gordon';
$data['route'] = 'myapi.test/validate-email/jQZSPFSZLuBqAdQofxtV5Bw2TK4ZcrNmoxFFR5ZvgGM48gHyKcxv7y6jHBaZhHIF';
$data['email'] = 'abc@gmail.com';
$data['title'] = 'Hi!!';
$data['body'] = 'Text here.';
SendEmailJob::dispatch('', $data,'','', $data['email'],'welcome');
}
SendEmailJob code uses sendMail function
sendMail($this->mailto, 'ConfirmaciĆ³n de solicitud', 'newRequest', $this->data, 'mi correo');
function sendMail($mailTo, $subject, $view, $data, $from)
{
try {
Mail::to($mailTo)->send(new SendMail($from, $data, $view, $subject));
return sendResponse('Ok');
} catch (\Exception $e) {
Log::debug($e->getMessage());
return sendExceptionError('Error 2',$e->getMessage());
}
}
SendMail is a mailable class
it works in postman with the route: myapi.test/api/v1/test, the job y executed and email is sent
but when I call this route from another project, it does not work
I try to debug it using logs, when use postman it works like a charm but when use it in a button it has an error: Expected response code "250" but got code "530", with message "530 5.7.1 Authentication required". then, the job does not execute.
it is so weird, I dont understand why
Help me please, sorry my bad english
Thanks
I trying to send email using a laravel job
SOLVED: I copied the email configuration from the .env file and config/mail.php in the api project to .env and config/mail.php in the app project. I don't know if it's the best or correct solution, but it works now. Thank you all for the answers.