The third day I suffer with the form of feedback, here is the link to the 
code, tell me where the error is. Although in pycharm it shows that the 
sending goes to the post office and the mail does not receive a message

from django.shortcuts import render
from django import forms
from django.http import HttpResponse
from django.core.mail import send_mail, BadHeaderError
import smtplib

def test_project(request):
    return render(request, 'test/home.html', locals())
def contactView(request):
   if request.method == 'POST':
      form = ContactForm(request.POST)
      #Если форма заполнена корректно,



class ContactForm(forms.Form):
   subject = forms.CharField(max_length = 100)
   sender = forms.EmailField()
   message = forms.CharField(widget = forms.Textarea(attrs = {'class': 
'form-control'}))
   copy = forms.BooleanField(required = False)

def contactView(request):
   if request.method == 'POST':
      form = ContactForm(request.POST)
      #Если форма заполнена корректно, сохраняем все введённые пользователем 
значения
      if form.is_valid():
         subject = form.cleaned_data['subject']
         sender = form.cleaned_data['sender']
         message = form.cleaned_data['message']
         copy = form.cleaned_data['copy']

         recipients = ['[email protected]']
         #Если пользователь захотел получить копию себе, добавляем его в список 
получателей
         if copy:
            recipients.append(sender)
         try:
            send_mail(subject, message, '[email protected]', recipients)
         except BadHeaderError: #Защита от уязвимости
            return HttpResponse('Invalid header found')
         #Переходим на другую страницу, если сообщение отправлено
         return render(request, 'contact.html')
   else:
      #Заполняем форму
      form = ContactForm()
   #Отправляем форму на страницу
   return render(request, 'home.html', {'form': form})


<!-- Contact Section -->
{% load staticfiles %}
    <section id="contact">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <h2>Contact Me</h2>
                    <hr class="star-primary">
                </div>
            </div>
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2">
                    <!-- To configure the contact form email address, go to 
mail/contact_me.php and update the email address in the PHP file on line 19. -->
                    <!-- The form should work on most web servers, but if the 
form is not working you may need to configure your web server differently. -->
                    <form action="" method="post">{% csrf_token %}
                        {{ form.non_field_errors }}
                        <div class="row control-group">
                            <div class="form-group col-xs-12 
floating-label-form-group controls">
                                     <label for="id_subject">Тема:</label>
                                        {{ form.subject.errors }}
                                        {{ form.subject }}
                                <input type="text" class="form-control" 
placeholder="Name" id="name" required data-validation-required-message="Please 
enter your name.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 
floating-label-form-group controls">
                                <label for="id_sender">Email Address</label>
                                     {{ form.sender.errors }}
                                     {{ form.sender }}
                                <input type="email" class="form-control" 
placeholder="Email Address" id="email" required 
data-validation-required-message="Please enter your email address.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 
floating-label-form-group controls">
                                <label for="phone">Phone Number</label>
                                <input type="tel" class="form-control" 
placeholder="Phone Number" id="phone" required 
data-validation-required-message="Please enter your phone number.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 
floating-label-form-group controls">
                                <label for="id_message">Message</label>
                                {{ form.message.errors }}
                               {{ form.message }}
                                <textarea rows="5" class="form-control" 
placeholder="Message" id="message" required 
data-validation-required-message="Please enter a message."></textarea>
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <br>
                        <div id="success"></div>
                        <div class="row">
                            <div class="form-group col-xs-12">
                                <button type="submit" class="btn btn-success 
btn-lg">Send</button>
                            </div>
                        </div>
                    </form>
                    </form>
                </div>
            </div>
        </div>
    </section>






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f6baa158-2f5a-46c4-a0fc-76fa82a94258%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to