Python联系表单

时间:2019-02-06 01:51:56

标签: django forms email contacts send

我使用Django创建了联系表格。除了无法在我的电子邮件帐户上看到发件人的电子邮件之外,所有内容都通过我的电子邮件帐户进行。如何修改我的代码,使发件人的电子邮件出现在我的帐户中?

观看次数

def contact(request):
    mapbox_access_token =    'pk.my_mapbox_access_token'
    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            sender_name = form.cleaned_data['name']
            emailFrom = form.cleaned_data['email']
            message = "{0} has sent you a new message:\n\n{1}".format(sender_name, form.cleaned_data['message'])


            form.save()
            try:
                send_mail('New Enquiry', message, emailFrom, ['**.***g@gmail.com'])
            except BadHeaderError:
                return HttpResponse('Invalid header found') 
            return redirect('success')

    return render(request, "contact.html",{'form': form})

0 个答案:

没有答案