Answer the question
In order to leave comments, you need to log in
How to send a letter template by email?
Hello.
Help to finish the function of sending the feedback form, so that a template comes to the mail in which there are all form fields.
def contact(reguest):
if reguest.method == 'POST':
form = ContactForm(reguest.POST)
# Если форма заполнена корректно, сохраняем все введённые пользователем значения
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
phone = form.cleaned_data['phone']
diament = form.cleaned_data['diament']
adress = form.cleaned_data['adress']
recepients = ['[email protected]']
# Положим копию письма в базу данных
MailBox.objects.create(subject=subject, sender=sender, phone=phone, diament=diament, adress=adress)
try:
send_mail(subject, adress, '[email protected]', recepients)
except BadHeaderError: #Защита от уязвимости
return HttpResponse('Invalid header found')
# Переходим на другую страницу, если сообщение отправлено
return HttpResponseRedirect('/zakaz/thanks/')
else:
form = ContactForm()
# Выводим форму в шаблон
return render_to_response('index.html', {'form': form})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question