def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = request.POST.get('subject', '') message = request.POST.get('message', '') name = request.POST.get('name', '') from_email = '%s <%s>' % (name, request.POST.get('from_email', '')) recipient_list = [mail_tuple[1] for mail_tuple in settings.ADMINS] try: t = loader.get_template('reviewapp/email_contact.txt') c = Context({ 'name': name, 'message': message, 'site_domain': Site.objects.get_current().domain, 'site_name': Site.objects.get_current().name, }) send_mail(subject, t.render(c), from_email, recipient_list, fail_silently=False) except BadHeaderError: return HttpResponse('Invalid header found.') messages.success(request, _('Message sent successfully.')) return HttpResponseRedirect('/contact/') else: messages.warning(request, _('Please fill out all fields correctly.')) else: if request.user.is_authenticated(): form = ContactForm(user=request.user) else: form = ContactForm() return render_to_response('reviewapp/contact.html', { 'form': form, }, context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = request.POST.get('subject', '') message = request.POST.get('message', '') name = request.POST.get('name', '') from_email = '%s <%s>' % (name, request.POST.get('from_email', '')) recipient_list = [mail_tuple[1] for mail_tuple in settings.ADMINS] try: t = loader.get_template('reviewapp/email_contact.txt') c = Context({ 'name': name, 'message': message, 'site': Site.objects.get_current() }) send_mail(subject, t.render(c), from_email, recipient_list, fail_silently=False) except BadHeaderError: return HttpResponse('Invalid header found.') return HttpResponseRedirect('/contact/?sent=ok') else: form = ContactForm() sent = bool(request.GET.get('sent', '')) return render_to_response('reviewapp/contact.html', { 'form': form, 'sent': sent }, context_instance=RequestContext(request))