HTML Email not sending when debug=false in django

I am making a website in which once the user registers for an event they are sent an email for the same confirming that they have registered for the event.

Now, the thing is I can send the html mail when DEBUG=True but I am not able to send the html mail when DEBUG=False in Django, neither I am able to detect why is it failing. Attaching code snippet.

Thanks for your help!

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = env('EMAIL_USE_TLS') == 'True'
EMAIL_HOST = env('EMAIL_HOST') #smtp.gmail.com
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
EMAIL_PORT = env('EMAIL_PORT') #587

views.py

            try:
                EventRegistration(event=event_obj, first_name=first_name, last_name=last_name,
                                  roll_number=roll_number,
                                  phone_number=phone_number, email=email, year_of_study=year_of_study,
                                  department=department).save()

                subject = f"Registration Successfull For {event_name}"
                html_message = render_to_string("mail related/Register Confirmation.html",
                                                context={'image': event_obj.banner_image, 'name': event_name,
                                                         'date': event_obj.event_date})
                plain_message = strip_tags(html_message)
                from_email = settings.EMAIL_HOST_USER
                to_list = [email]
                send_mail(subject, plain_message, from_email, to_list, html_message=html_message)

                messages.info(request, 'Successfully registered')
            except e:
                messages.warning(request, 'Failed to Register')

        return render(request, 'main/register.html', context)
    except Exception:
        return redirect('events'
Back to Top