hi guys i'm having some trouble with my production application:: in a few words what it should do is sending an email using SendinBlue API everithing is fine when in local but the application begins to act weirdly in production when a request with an email-address is sent from my frontend this function should fire
public function checkEmail(Request $request)
{
$email = $request->input('email');
// Controlla se l'email è presente nel database
$emailRecord = Email::where('email', $email)->first();
if ($emailRecord) {
// Se l'email è già presente nel database e associata a un token, ritorna il token
error_log('mail gia esistente');
$token = $emailRecord->token()->first();
error_log('token= '. $token->token);
error_log('code= '. $code->promo_code);
$code = $token->codes()->first();
return $this->sendEmail($request, 285, $code->promo_code);
} else {
// Se l'email non è presente nel database, crea un nuovo token e associarlo all'email
$tokenValue = Str::random(16);
try {
$token = new Token(['token' => $tokenValue]);
$token->save();
$newEmail = new Email(['email' => $email, 'token_id' => $token->id]);
$newEmail->save();
error_log('nuova mail aggiunta');
return $this->sendEmail($request, 284);
}catch (\Exception $e){
error_log('errore nell aggiunta della nuova mail');
return response()->json(['error' => 'Si è verificato un errore durante la creazione della email e del token'], 500);
}
}
}
then this function is called to send the mail
public function sendEmail(Request $request, $templateId, $code = "")
{
error_log('invio mail...');
$emailTo = $request->input('email');
// Trova il token nel database in base all'email
$token = Email::where('email', $emailTo)->first()->token;
// Inserisci qui la tua chiave API di Sendinblue
$apiKey = Env::get("API_KEY");
// Configura l'API client di Sendinblue
$config = Configuration::getDefaultConfiguration()->setApiKey('api-key', $apiKey);
$apiInstance = new TransactionalEmailsApi(new Client(), $config);
// Prepara i dati dell'email
$redeemUrl = Env::get('APP_URL') . "/code?token=".$token->token;
$htmlContent = '<a href="' . $redeemUrl . '">LINK AL CODICE SCONTO</a> TOKEN=' . $token->token;
$emailData = new SendSmtpEmail([
'templateId' => $templateId,
'params' => [
'LINK' => $redeemUrl,
'CODE' => $code,
],
'to' => [['email' => $emailTo]],
]);
try {
// Invia l'email utilizzando le API di Sendinblue
$result = $apiInstance->sendTransacEmail($emailData);
// Ritorna una risposta positiva al frontend (ad esempio, una risposta JSON vuota)
return response()->json([], 200);
} catch (\Exception $e) {
error_log('errore nell invio della mail');
// Gestisci eventuali errori nell'invio dell'email
return response()->json(['error' => $e->getMessage()], 500);
}
}
What I'm receiving in the console when I submit an already saved email address is a generic 500 error with "Internal Server Error" message
looks like thet when in production the error_log('code='. $code->promo_code)
is not showing up in the console
any idea what the problem could be? or any idea on how should i debug the problems?