I'm not sure if this is a problem with my code, or if there is some internal error. The code for sending an email seems to be pretty straightforward and after a couple days of poking around, I can't find where the error in my code is.
When running an email, my browser spins for minutes and then PA sends me PA specific an error page saying that something went wrong and there was an error "Error code: 504-loadbalancer". I've noticed some others have been having this error recently ( https://www.pythonanywhere.com/forums/topic/987/ ), so now I'm wondering if it's not a problem with my code? Any thoughts?
#settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'myemail@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = True
#views.py
from django.core.mail import send_mail
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
send_mail(
cd['subject'],
cd['body'],
cd.get('email', 'myemail@gmail.com'),
['myemail@gmail.com'],
fail_silently=False)
return render(request, 'content/generictext.html',
{'text':'Your contact has been successfully sent, thank you.'})
else:
form = ContactForm()
return render(request, 'content/contact.html', {'form': form})