So i was this application in which when a user fill the form, I get an email with their details so that i can contact them. But when ever the form is submitted, it shows me this error.
I couldn't find whats bugging the code. All the credentials are in place. I am using SendingBlue smtp server for this project. Have a look at my code:
views.py
from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
# Create your views here.
def home(request):
return render(request, 'index.html')
def register(request):
if request.method == 'GET':
return render(request, 'register.html')
else:
name = request.POST['full-name']
email = request.POST['email']
phone = request.POST['phone']
nationality = request.POST['nationality']
try:
send_mail("Trial Application", name + email + phone + nationality, '*my email*', ['* same email*'])
except BadHeaderError:
return HttpResponse('Something Went Wrong')
return redirect(request, 'index.html')
return render(request, 'register.html')
settings.py
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp-relay.sendinblue.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "*my email*"
EMAIL_HOST_PASSWORD = "password"
register.html
<form action="" method="post" class="form">
{% csrf_token %}
<fieldset>
<legend>Please fill in the required details</legend>
<input type="text" name="full-name" placeholder="Full Name" id="">
<input type="email" name="email" placeholder="Email" id="">
<input type="tel" name="phone" placeholder="Phone Number" id="">
<input type="text" name="nationality" placeholder="Nationality" id="">
<input type="submit" value="Submit" id="submit">
</fieldset>
</form>
I would really appreciate if someone would help me eradicate this bug. Thanks in advance.