Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. widok:
  2.  
  3. def contact(request):
  4.     title = "Contact me"
  5.     form = ContactForm(request.POST or None)
  6.     if form.is_valid():
  7.         form_email = form.cleaned_data.get("email")
  8.         form_message = form.cleaned_data.get("message")
  9.         form_full_name = form.cleaned_data.get("full_name")
  10.         subject = "Site contact form"
  11.         from_email = settings.EMAIL_HOST_USER
  12.         to_email = [from_email, ]
  13.         contact_message = " %s: %s via %s" % (form_full_name, form_message, form_email)
  14.         send_mail(subject,
  15.                   contact_message,
  16.                   from_email,
  17.                   [to_email],
  18.                   fail_silently=False)
  19.     context = {
  20.         "title": title,
  21.         "form": form,
  22.     }
  23.  
  24.     return render(request, "forms.html", context)
  25.  
  26.  
  27. forms:
  28.  
  29. class ContactForm(forms.Form):
  30.     full_name = forms.CharField(max_length=24)
  31.     email = forms.EmailField()
  32.     message = forms.CharField()
  33.  
  34.  
  35. settings:
  36. EMAIL_HOST = 'smtp.gmail.com'
  37. EMAIL_HOST_USER = 'mojmail@mail.com'
  38. EMAIL_HOST_PASSWORD = 'moje_haslo'
  39. EMAIL_PORT = 587
  40. EMAIL_USE_TLS = True
  41. '''
  42.    if using gmail, you will need to unlock captcha to enable django
  43.    to send for you:
  44.    https://accounts.google.com/displayunlockcaptcha
  45. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement