Created
October 24, 2013 02:49
-
-
Save chriskief/7130488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from app.lib.amazonses import SESMessage | |
def contact(request): | |
if request.method == 'POST': | |
form = ContactForm(request.POST) | |
if form.is_valid(): | |
# grab the form data | |
name = form.cleaned_data['name'] | |
email = form.cleaned_data['email'] | |
subject = form.cleaned_data['subject'] | |
body = form.cleaned_data['body'] | |
recipient = '[email protected]' | |
# render the template with the submitted data | |
rendered = render_to_string('email/contact.html', {'name': name, 'email': email, 'subject': subject, 'body': body}) | |
# create the message and send the email | |
# the from address must be a verified sender in SES | |
msg = SESMessage('[email protected]', recipient, subject) | |
msg.text = rendered | |
msg.html = rendered + ' html' | |
msg.send() | |
messages.add_message(request, messages.INFO, 'Your contact enquiry was successfully sent. Thank you!') | |
return HttpResponseRedirect(reverse('contact')) | |
else: | |
form = ContactForm() | |
return render(request, 'contact.html', {'form': form}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment