0

so I'm wanting to make this form where the client fills their name, email and a message. Then that message and their name is sent to my mail address and another mail is sent from my address to the clients one telling that their mail was sent successfully. I already did this on another project and literally just copied changing the name of the functions n stuff but it doesn't work.

views.py

def send_email(email):
    context = {'email': email}
    template = get_template('emails/message-confirmation.html')
    content = template.render(context)
    email = EmailMultiAlternatives(
        'Test email',
        'AmiSalta message confirmation',
        settings.EMAIL_HOST_USER,
        [email]
    )
    email.attach_alternative(content, 'text/html')
    email.send()


def function(request):
    form = ContactForm_es()
    if request.method == 'POST':
        email = request.POST.get('email')
        send_mail(email)
        form = ContactForm_es(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            full_name = form.cleaned_data['full_name']
            body = form.cleaned_data['body']
            send_mail(full_name,body,email, ['******@gmail.com'])

    return render(request, 'es/home.html', {
            'form': form,
    })

I'm going crazy bc is the last thing I need to do and I already did once but I just can't make it work. Please if someone knows what's wrong let me know, thanks in advance.

Enmanuel V
  • 31
  • 1
  • 5

3 Answers3

0

I was getting the same issue you are having and the thing I was doing wrong was in the URLs.py file I was calling send_mail directly instead of the veiw_func that sends the mail that is why it was saying all the three required parameters are missing.

check your URLs.py file you might be having the same issue

MuTanT46
  • 56
  • 6
0

Check if you use your send_email in urls.py instead of send_mail. The name of your function is very similar to the django's send_mail() function. You can easily confuse yourself.

JZah
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 09 '22 at 00:47
0

Change the name of function def send_email(email): to something def mailtest(email): you are getting thise error beacause you are trying to overwrite the function

Roshan yadav
  • 101
  • 1
  • 5