from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from django.template import RequestContext
from .forms import ContactForm

# Create your views here.
def home(request):
    return render(request, 'base/index.html')

def about(request):
    return render(request, 'base/about.html')

def contact(request):
    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            subject    = form.cleaned_data['subject']
            from_email = form.cleaned_data['from_email']
            message    = form.cleaned_data['message']

            try:
                send_mail(subject, message, from_email, ['<EMAIL>'])
            except BadHeaderError:
                return HttpResponse('Invalid header found.')
            return redirect('/')
    return render(request, 'base/contact.html', {'form': form})
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from django.template import RequestContext
from .forms import ContactForm

# Create your views here.
def home(request):
    return render(request, 'base/index.html')

def about(request):
    return render(request, 'base/about.html')

def contact(request):
    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            subject    = form.cleaned_data['subject']
            from_email = form.cleaned_data['from_email']
            message    = form.cleaned_data['message']

            try:
                send_mail(subject, message, from_email, ['<EMAIL>'])
            except BadHeaderError:
                return HttpResponse('Invalid header found.')
            return redirect('/')
    return render(request, 'base/contact.html', {'form': form})
# Create your views here.