Guest User

Untitled

a guest
Mar 1st, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. def email(request):
  2. if request.method=='POST':
  3. form = ContactForm(request.POST)
  4. form.email = request.POST.get('email', '')
  5. form.subject = request.POST.get('subject', '')
  6. form.message = request.POST.get('message', '')
  7. if form.is_valid():
  8. subject = form.cleaned_data['subject']
  9. message = form.cleaned_data['message']
  10. sender = form.cleaned_data['email']
  11. cc_myself = form.cleaned_data['cc_myself']
  12. recipients = ['unionjunior1@gmail.com']
  13.  
  14. if cc_myself:
  15. recipients.append(email)
  16. send_mail(subject, message, sender, recipients, fail_silently=False)
  17. return HttpResponseRedirect('thanks')
  18. else:
  19. form.errors
  20. else:
  21. form = ContactForm()
  22. return render(request, 'main.html', {'form': form})
  23.  
  24. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  25. EMAIL_USE_TLS = True
  26. EMAIL_HOST = 'smtp.gmail.com'
  27. EMAIL_PORT = 587
  28. EMAIL_HOST_USER = 'unionjunior1@gmail.com'
  29. EMAIL_HOST_PASSWORD = '***'
Add Comment
Please, Sign In to add comment