title: Handling contact form in Django, email not sent
body: <p>I have an application whereby a user can contact me by filling out a form and in the form the user just has to fill in his details and his email and subject. </p>
  
  <p>The code throws no error but I could <em>not receive the mail after setting up everything</em>, but the contact details gets stored in the database as I want it to be stored.</p>
  
  <p>Below is my code.</p>
  
  <p><strong>Models.py</strong> </p>
  
  <pre><code>class Contact(models.Model):
      name = models.CharField(max_length=100)
      message = models.TextField()
      sender = models.EmailField()
      phone = models.CharField(max_length=10)
      cc_myself = models.BooleanField(blank=True)
      time = models.DateTimeField(auto_now_add=True, db_index=True)
  
      def __str__(self):
          return 'Message for {}'.format(self.sender)
  </code></pre>
  
  <p><strong>Forms.py</strong></p>
  
  <pre><code>class ContactForm(forms.ModelForm):
  
      class Meta:
          model = Contact
          fields = ['name', 'sender', 'phone', 'message', 'cc_myself']
  </code></pre>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>def contact(request):
      if request.method == 'POST':
          contact_form = ContactForm(request.POST)
  
          if contact_form.is_valid():
              name = contact_form.cleaned_data['name']
              message = contact_form.cleaned_data['message']
              sender = contact_form.cleaned_data['sender']
              phone = contact_form.cleaned_data['phone']
              cc_myself = contact_form.cleaned_data['cc_myself']
  
              recipients = ['xxxx@gmail.com']
              if cc_myself:
                  recipients.append(sender)
  
              send_mail(name, message, sender, recipients)
              contact_form.save()
              messages.success(request, 'Message sent successfully')
              return redirect('contact:contact')
          else:
              messages.error(request, 'Error sending your Message')
  
      else:
          contact_form = ContactForm(request.POST)
  
      context = {
          "contact_form": contact_form,
      }
      template = 'contact.html'
      return render(request, template, context)
  </code></pre>
  
  <p><strong>gmail server</strong></p>
  
  <pre><code>EMAIL_HOST = 'smtp.gmail.com'
  EMAIL_HOST_USER = 'xxx@gmail.com'
  EMAIL_HOST_PASSWORD = 'xxxx'
  EMAIL_PORT = '587'
  EMAIL_USE_TLS = True
  </code></pre>
  
  <p><strong>terminal output</strong></p>
  
  <pre><code>MIME-Version: 1.0
  Content-Type: text/plain; charset="utf-8"
  Content-Transfer-Encoding: 7bit
  Subject: adie Ugbe
  From: abcd@gmail.com
  To: xxxx@gmail.com
  Date: Sun, 07 Jan 2018 11:11:10 -0000
  Message-ID: &lt;20180107111110.29855.10393@1.0.0.127.in-addr.arpa&gt;
  
  oh oh no ooo dddddddd se skan
  -------------------------------------------------------------------------------
  Successful
  </code></pre>