问题描述
我创建了一个联系表单,以便在用户填写电子邮件时向我发送电子邮件。一切似乎都正常,我收到了我的gmail邮件,但我是从我自己那里收到的,而不是从填写的“电子邮件表单”中收到的。
例如,我在我的网站上填写表格:
- 主题:TEST
- 电子邮件:[email protected]
- 消息:您好
当我检查自己的gmail帐户时,我收到了消息:
- 来自电子邮件:[email protected] -吗?
- 发送至电子邮件:[email protected]
- 日期:2020年9月17日,14:05
- 主题:TEST
- 邮寄人:gmail.com
- 消息:您好
我的表格:
class EmailForm(forms.Form):
subject = forms.CharField(max_length=50,widget=forms.TextInput(attrs={'class': 'form-control','placeholder': 'Your subject'}))
email = forms.EmailField(widget=forms.TextInput(attrs={'class': 'form-control','placeholder': 'Your email'}))
message = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control','placeholder': 'Your message'}))
我的观点:
def contact(request):
form = EmailForm()
if request.method =="POST":
form = EmailForm(request.POST)
if form.is_valid():
subject = request.POST['subject']
message = request.POST['message']
email = request.POST['email']
send_mail(
subject,message,email,['[email protected]'],fail_silently=False,)
context = {'subject':subject}
return render(request,'base/contact.html',context)
context = {'form':form}
return render(request,context)
我的设置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)