from django.shortcuts import render
from django.contrib import messages
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings

from .forms import ContactForm


def contact(request):
    """ Contact Stumps & Studs form. """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact_message = {
                'full_name': request.POST['full_name'],
                'email': request.POST['email'],
                'message': request.POST['message'],
            }
            form.save()

            # Send the user an email acknowledging their message.
            cust_email = request.POST['email'],
            subject = render_to_string(
                'contact/confirmation_emails/confirmation_email_subject.txt')
            body = render_to_string(
                'contact/confirmation_emails/confirmation_email_body.txt',
                {'contact_message': contact_message})
            email_from = settings.EMAIL_HOST_USER
            recipient_list = cust_email
            send_mail(
                subject,
                body,
                email_from,
                recipient_list,
            )

            messages.success(request, 'Thank you for your message.  \
                Someone will respond via email soon.')
        else:
            messages.error(request, 'Message failed.  Please ensure the \
                form is valid.')

    form = ContactForm()
    template = 'contact/contact.html'
    context = {
        'form': form,
    }

    return render(request, template, context)

91c3c782a46ab65ed4a3810b2fc1df105fa3672f
<mask token>

<mask token>


def contact(request):
    """ Contact Stumps & Studs form. """
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact_message = {'full_name': request.POST['full_name'],
                'email': request.POST['email'], 'message': request.POST[
                'message']}
            form.save()
            cust_email = request.POST['email'],
            subject = render_to_string(
                'contact/confirmation_emails/confirmation_email_subject.txt')
            body = render_to_string(
                'contact/confirmation_emails/confirmation_email_body.txt',
                {'contact_message': contact_message})
            email_from = settings.EMAIL_HOST_USER
            recipient_list = cust_email
            send_mail(subject, body, email_from, recipient_list)
            messages.success(request,
                'Thank you for your message.                  Someone will respond via email soon.'
                )
        else:
            messages.error(request,
                'Message failed.  Please ensure the                 form is valid.'
                )
    form = ContactForm()
    template = 'contact/contact.html'
    context = {'form': form}
    return render(request, template, context)

from django.shortcuts import render
from django.contrib import messages
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings
from .forms import ContactForm


def contact(request):
    """ Contact Stumps & Studs form. """
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact_message = {'full_name': request.POST['full_name'],
                'email': request.POST['email'], 'message': request.POST[
                'message']}
            form.save()
            cust_email = request.POST['email'],
            subject = render_to_string(
                'contact/confirmation_emails/confirmation_email_subject.txt')
            body = render_to_string(
                'contact/confirmation_emails/confirmation_email_body.txt',
                {'contact_message': contact_message})
            email_from = settings.EMAIL_HOST_USER
            recipient_list = cust_email
            send_mail(subject, body, email_from, recipient_list)
            messages.success(request,
                'Thank you for your message.                  Someone will respond via email soon.'
                )
        else:
            messages.error(request,
                'Message failed.  Please ensure the                 form is valid.'
                )
    form = ContactForm()
    template = 'contact/contact.html'
    context = {'form': form}
    return render(request, template, context)

from django.shortcuts import render
from django.contrib import messages
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings

from .forms import ContactForm


def contact(request):
    """ Contact Stumps & Studs form. """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact_message = {
                'full_name': request.POST['full_name'],
                'email': request.POST['email'],
                'message': request.POST['message'],
            }
            form.save()

            # Send the user an email acknowledging their message.
            cust_email = request.POST['email'],
            subject = render_to_string(
                'contact/confirmation_emails/confirmation_email_subject.txt')
            body = render_to_string(
                'contact/confirmation_emails/confirmation_email_body.txt',
                {'contact_message': contact_message})
            email_from = settings.EMAIL_HOST_USER
            recipient_list = cust_email
            send_mail(
                subject,
                body,
                email_from,
                recipient_list,
            )

            messages.success(request, 'Thank you for your message.  \
                Someone will respond via email soon.')
        else:
            messages.error(request, 'Message failed.  Please ensure the \
                form is valid.')

    form = ContactForm()
    template = 'contact/contact.html'
    context = {
        'form': form,
    }

    return render(request, template, context)
