I have a contactform on my site.
When submitted a mail is sent to me. But I also want to send the user a mail, letting the user know that I have received the form submission.
When I try to put the email
value as a recipient, I get this error: AssertionError: "to" argument must be a list or tuple
Anyone see what is wrong with my code?
def show_contactform(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
f = ContactForm(request.POST)
f.save()
email = form.cleaned_data['email']
subject = "New contact from website"
recipients = ['contact@company.com']
rendered = render_to_string('forms/email_body.html', {'form':form)
to_user_subject = "Contact registred"
to_user_rendered = render_to_string('form/to_user_email_contact.html', {'form_headline':subject})
#Send content to celery worker for asynchronous mail outbox - sending to company
tasks.send_email.delay(subject=subject, rendered=rendered, email=email, recipients=recipients)
#Send content to celery worker for asynchronous mail outbox - sending to the user who sent the form
tasks.send_email.delay(subject=to_user_subject, rendered=to_user_rendered, email=recipients, recipients=email)
return HttpResponseRedirect('/form/contact/success/')
else:
form = ContactForm() # An unbound form
return render(request, 'contact/form.html', {
'form': form,
})
@task()
def send_email(subject, rendered, email, recipients):
msg = EmailMultiAlternatives(subject, rendered, email, recipients)
msg.attach_alternative(rendered, "text/html")
msg.send()