B
B
blazer052017-01-21 18:05:48
Django
blazer05, 2017-01-21 18:05:48

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

1 answer(s)
S
sim3x, 2017-01-21
@blazer05

https://github.com/django/django/blob/master/djang...
stackoverflow.com/questions/36958543/django-render...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question