I've create following form:
class ContactForm(forms.Form):
full_name = forms.CharField(required=False)
email = forms.EmailField()
message = forms.CharField(widget=forms.Textarea(attrs={'class':'special', 'size': '40'}))
But when I add data in Message field with some data it isn't coming up in my email associated with this form with settings mentioned in Settings.py. But full_name and email is coming up fine.
My view is:
def contact(request):
title = "Contact Us"
form = ContactForm(request.POST or None)
if form.is_valid():
form_email = form.cleaned_data.get('email')
form_message = form.cleaned_data.get('message')
form_full_name = form.cleaned_data.get('full_name')
subject = "Site Contact Form"
from_email = settings.EMAIL_HOST_USER
to_email = [from_email, [email protected]']
contact_message = "%s: %s via %s"%(form_full_name, form_message, form_email)
html_template = "<h1>Hello There</h1>"
send_mail(subject, contact_message, from_email, to_email, html_message=html_template, fail_silently=True)
context = {
"form":form,
"title": title
}
return render(request, 'contact/form.html', context)
Also I need to know what would be the best option to create some form to recieve information directly to my email. Should I use models based form or simple form without models? Please advise as my message field text is not coming up in email but Name and email is coming up fine.
Try this,
message = forms.CharField(widget=forms.TextInput(attrs={'class':'special', 'size': '40'}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With