Reputation: 637
I just finished setting up a contact form thanks to some tutorial, but on the tutorial I took it says I have to setup sendgrid or some other service to get the reply. but thing is they aren't free.
Is there a way to get the emails for free?
def contact(request):
form_class = ContactForm
if request.method == 'POST':
form = form_class(data=request.POST)
if form.is_valid():
contact_name = request.POST.get('contact_name','')
contact_email = request.POST.get('contact_email','')
form_content = request.POST.get('content','')
template=get_template('contact_template.txt')
context = Context({
'contact_name':contact_name,
'contact_email':contact_email,
'form_content':form_content,
})
content = template.render(context)
email = EmailMessage(
"New Contact form submisssion",
content,
"your website"+'',
['[email protected]'],
headers = {'Reply-To':contact_email})
email.send()
return redirect('contact')
return render(request, 'contact.html', {
'form':form_class,
})
I have this in txt file, and this is what I get in email
Contact Name:
Email:
Content:
Upvotes: 0
Views: 180
Reputation: 600051
I don't know why you're asking about email services, they have nothing to do with your question. Your email is blank because you don't seem to have any variable placeholders in your template. Add {{ contact_name }}
etc to fill in the data, just as you would with an HTML template.
Upvotes: 3