i am currently building a contact us form.
when my users filed the form  and submit  it will send them welcome message 
and send also forward the user data to my email.

 i was able to used mailMultiAlternatives  to achieve  sending  the html 
template to my users with the code below.

EmailMultiAlternatives email class doesn't  allow sending multiple message 
to different email address. 


class Conactme(CreateView):
    form_class = Contactusform
    context_object_name = "forms"
    template_name = "registration/contactus.html"
    success_url = reverse_lazy('home')

    def form_valid(self, form):
        if form.is_valid():


            email = form.cleaned_data['email']
            full_name = form.cleaned_data['full_name']
            purpose = form.cleaned_data['purpose']
            phone = form.cleaned_data['phone']
            comment = form.cleaned_data['comment']
            form.save()
        content = {"fullname": full_name,
                   "phone":  phone,
                   "purpose": purpose
                   }
        userssubject = "Users Registrations"
        adminsubject = "Welcome message"
        html_message = render_to_string(
            template_name="emails/email_comfirmation.html", context=content)
        meg = EmailMultiAlternatives(
            adminsubject, full_name, EMAIL_HOST_USER, [email])
        meg.attach_alternative(html_message, 'text/html')
        meg.send()
        if meg.send:
         return render(self.request, "registration/sucesss.html")

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cfabe10e-0dae-4ec2-9936-b6061a4ae146n%40googlegroups.com.

Reply via email to