在电子邮件模板中发送电子邮件和名称

时间:2019-04-16 12:43:38

标签: html django

我想通过与Django建立的网站将访问者的姓名,电子邮件,主题和消息发送到我的电子邮件地址。

mysite / views.py

def contact(request):
    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            from_email = form.cleaned_data['from_email']
            message = form.cleaned_data['message']
            try:
                send_mail(subject, message, from_email, ['my@mail.com'])
            except BadHeaderError:
                return HttpResponse('Invalid header found.')
        return HttpResponse('Thanks for your email')
return render(request,'giris/contact.html',{'form': form})
  

     {%封锁内容%}      {%load widget_tweaks%}          

联系我们

               {%csrf_token%}          {{form.as_p}}                      {%endblock%}

     

我想通过django-widget-tweaks显示并通过电子邮件发送我准备的模板。

1 个答案:

答案 0 :(得分:0)

            get_cust = RegularCustomerMaster.objects.get(id=instance)
            Message = New_Customer.Message.replace('{customer_email}', get_cust.Email)

现在{customer_email}是您的关键,如果您通过电子邮件传递,实际的电子邮件将发送