我通过遵循在线教程来创建电子商务网站,现在已经达到创建表单的目的,然后我应该将电子邮件发送给完成表单的任何人。但是,电子邮件没有发送。
Settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password123'
EMAIL_PORT = '587'
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = 'testing@testing.com'
viwes.py
from django.shortcuts import render
from django.core.mail import send_mail
from django.conf import settings
from .forms import contactForm
# Create your views here.
def contact(request):
form = contactForm(request.POST or None)
if form.is_valid():
name = form.cleaned_data['name']
comment = form.cleaned_data['comment']
subject = 'Message from MYSITE.com'
message = '%s %s' %(comment, name)
emailFrom = form.cleaned_data['email']
emailTo = [settings.EMAIL_HOST_USER]
send_mail(subject, message, emailFrom, emailTo, fail_silently =True)
context = locals()
template = 'contact.html'
return render(request,template,context)
我没有收到错误消息,但是我没有收到电子邮件