thanks very much but base on your code you are sending all the message to user. i want to send a specific message to admin emails like form input data than and also send to user such as welcome message
On Saturday, July 3, 2021 at 2:10:21 PM UTC+1 get...@gmail.com wrote: > from django.conf import settings > from django.core.mail import send_mail > > def valorant_view(request): > if (valorant_registration.objects.count() <= 160): > if request.method == 'POST': > first_name = request.POST['first_name'] > last_name = request.POST['last_name'] > email = request.POST['email'] > mobile_number = request.POST['mobile_number'] > branch = request.POST['mobile_number'] > dicord_id = request.POST['dicord_id'] > valorant_id = request.POST['valorant_id'] > college_name = request.POST['college_name'] > student_id = request.FILES['student_id'] > > valorant = valorant_registration(first_name=first_name, > last_name=last_name, email=email, > mobile_number=mobile_number, > branch=branch, dicord_id=dicord_id, valorant_id=valorant_id, college_name= > college_name, student_id=student_id) > > valorant.save() > print('Event Registration Done Succesfully') > subject = 'Techela 6.0 Registration' > from_email = settings.DEFAULT_FROM_EMAIL > template = render_to_string( > 'thank-you.html', {'name': first_name + ' ' + last_name, > 'event': 'Valorant'}) > message = 'Test' > html_message = template > > send_mail(subject, message, from_email, [email], > fail_silently=False, html_message=html_message) > return HttpResponse('Done') > > else: > print('Not there events') > return redirect('warning.html2') > > else: > return HttpResponse('Registration closed') > > On Sat, Jul 3, 2021 at 6:05 PM SKYLINE TV <skyli...@gmail.com> wrote: > >> 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...@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 >> >> <https://groups.google.com/d/msgid/django-users/cfabe10e-0dae-4ec2-9936-b6061a4ae146n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/5292f40b-a083-4a89-a05f-78a224f3fc77n%40googlegroups.com.