phantasma/app/contact/views.py

24 lines
861 B
Python
Raw Permalink Normal View History

2021-10-26 16:02:11 +00:00
from django.conf import settings
2021-10-26 16:02:55 +00:00
from django.core.mail import EmailMessage
2021-10-26 15:47:06 +00:00
from django.shortcuts import render
2023-03-02 14:59:40 +00:00
from ..utils import render_to_json_response
2021-10-26 15:47:06 +00:00
from . import forms
from . import models
def index(request):
2021-10-28 11:10:26 +00:00
success = True
2021-10-26 15:47:06 +00:00
if request.method == 'POST':
form = forms.ContactForm(request.POST)
if form.is_valid():
message = 'From: %s\n\n%s' % (form.cleaned_data['email'], form.cleaned_data['message'])
2023-03-02 14:59:40 +00:00
subject = 'phantas.ma contact message'
2021-10-26 15:47:06 +00:00
from_ = settings.CONTACT_FROM_EMAIL
2021-10-26 16:51:21 +00:00
to = [settings.CONTACT_TO_EMAIL]
2021-10-26 15:47:06 +00:00
msg = EmailMessage(subject, message, from_, to, reply_to=[form.cleaned_data['email']])
msg.send(fail_silently=True)
else:
2021-10-28 11:10:26 +00:00
success = False
else:
success = False
return render_to_json_response({'success': success})