Guest User

Untitled

a guest
May 13th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. SEND_GRID_API_KEY = 'APIGENERATEDONSENDGRID'
  2. EMAIL_HOST = 'smtp.sendgrid.net'
  3. EMAIL_HOST_USER = 'mySENDGRIDusername'
  4. EMAIL_HOST_PASSWORD = 'myEMAILpassword' #sendgrid email
  5. EMAIL_PORT = 587
  6. EMAIL_USE_TLS = True
  7. DEFAULT_FROM_EMAIL = 'MYEMAIL' #sendgrig email
  8.  
  9. from django.shortcuts import render
  10. from django.http import HttpResponse
  11. from .forms import ContactForm
  12. from django.core.mail import send_mail
  13. from django.conf import settings
  14. from django.template.loader import get_template
  15.  
  16.  
  17. def index(request):
  18. return render(request, 'index.html')
  19.  
  20. def contact(request):
  21.  
  22. success = False
  23. form = ContactForm(request.POST)
  24. if request.method == 'POST':
  25. name = request.POST.get("name")
  26. email = request.POST.get("email")
  27. message = request.POST.get("message")
  28.  
  29. subject = 'Contact from MYSITE'
  30.  
  31. from_email = settings.DEFAULT_FROM_EMAIL
  32. to_email = [settings.DEFAULT_FROM_EMAIL]
  33.  
  34. message = 'Name: {0}nEmail:{1}n{2}'.format(name, email, message)
  35.  
  36. send_mail(subject, message, from_email, to_email, fail_silently=True)
  37.  
  38. success = True
  39. else:
  40. form = ContactForm()
  41. context = {
  42. 'form': form,
  43. 'success': success
  44. }
  45. return render(request, 'contact.html',context)
Add Comment
Please, Sign In to add comment