I wrote code in basic HTML tags like and there was no problem. Mail was sent correctly. But when I changed its place and HTML tags mail function didn't work. What problem can be?
It works
<h1>Contact Us</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div class="form-actions">
<button type="submit">Send</button>
</div>
</form>
It doesn't work.
<form class="contact-form" action="" method="GET">
{% csrf_token %}
{% for field in form %}
{{ field|add_class:"input" }}
{% endfor %}
<button class="button" type="submit">Send</button>
</form>
views.py
def index(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST or None)
if form.is_valid():
fullname = form.cleaned_data['fullname']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(fullname, message, from_email,
['[email protected]'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('home')
context['form'] = form
return render(request, "index.html", context)
post