Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from django.core.mail import send_mail, BadHeaderError
  2. from django.http import HttpResponse, HttpResponseRedirect
  3.  
  4. def send_email(request):
  5.     subject = request.POST.get('subject', '')
  6.     message = request.POST.get('message', '')
  7.     from_email = request.POST.get('from_email', '')
  8.     if subject and message and from_email:
  9.         try:
  10.             send_mail(subject, message, from_email, ['admin@example.com'])
  11.         except BadHeaderError:
  12.             return HttpResponse('Invalid header found.')
  13.         return HttpResponseRedirect('/contact/thanks/')
  14.     else:
  15.         # In reality we'd use a form class
  16.         # to get proper validation errors.
  17.         return HttpResponse('Make sure all fields are entered and valid.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement