Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SEND_GRID_API_KEY = 'APIGENERATEDONSENDGRID'
- EMAIL_HOST = 'smtp.sendgrid.net'
- EMAIL_HOST_USER = 'mySENDGRIDusername'
- EMAIL_HOST_PASSWORD = 'myEMAILpassword' #sendgrid email
- EMAIL_PORT = 587
- EMAIL_USE_TLS = True
- DEFAULT_FROM_EMAIL = 'MYEMAIL' #sendgrig email
- from django.shortcuts import render
- from django.http import HttpResponse
- from .forms import ContactForm
- from django.core.mail import send_mail
- from django.conf import settings
- from django.template.loader import get_template
- def index(request):
- return render(request, 'index.html')
- def contact(request):
- success = False
- form = ContactForm(request.POST)
- if request.method == 'POST':
- name = request.POST.get("name")
- email = request.POST.get("email")
- message = request.POST.get("message")
- subject = 'Contact from MYSITE'
- from_email = settings.DEFAULT_FROM_EMAIL
- to_email = [settings.DEFAULT_FROM_EMAIL]
- message = 'Name: {0}nEmail:{1}n{2}'.format(name, email, message)
- send_mail(subject, message, from_email, to_email, fail_silently=True)
- success = True
- else:
- form = ContactForm()
- context = {
- 'form': form,
- 'success': success
- }
- return render(request, 'contact.html',context)
Add Comment
Please, Sign In to add comment