i am getting this error down  when trying to submit  my form data to email
{{ ValueError at /contact

too many values to unpack (expected 4)

Request Method: POST
Request URL: http://localhost:8000/contact
Django Version: 3.2.4
Exception Type: ValueError
Exception Value:

too many values to unpack (expected 4)

Exception Location:
C:\Users\RDM\Envs\env\lib\site-packages\django\core\mail\__init__.py, line
83, in <listcomp>
Python Executable: C:\Users\RDM\Envs\env\Scripts\python.exe
Python Version: 3.9.6
Python Path:

['C:\\Users\\RDM\\Desktop\\Web\\KVC\\KVC',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\python39.zip',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\DLLs',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\lib',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39',
 'C:\\Users\\RDM\\Envs\\env',
 'C:\\Users\\RDM\\Envs\\env\\lib\\site-packages']



Mon, 05 Jul 2021 15:04:30 +00
}}}


my settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '587'
EMAIL_HOST_USER = 'myacco...@gmail.com'
EMAIL_HOST_PASSWORD = 'almxfemqayldytab'
EMAIL_USE_TLS = True

here is my views.py

def contact(request):
    if request.method == 'POST':
        f_name = request.POST['name']
        f_email = request.POST['email']
        f_subject = request.POST['subject']
        f_message = request.POST['message']

        # send mail function
        datatuple = (
            ('f_name','f_subject', 'f_message','f_email',
        ['mygm...@gmail.com']),
            # second person
            ('f_name','f_subject', 'f_message','f_email',
        ['sec...@gmail.com'])
        )
        send_mass_mail(datatuple)

        if send_mass_mail(datatuple):
            messages.info(request,'thank you for contacting us')
            return redirect('contact')
        else:
            messages.info(request, 'try again sorry for inconveniency')
            return redirect('contact')
    else:
        messages.info(request, 'try again sorry for inconveniency')
        return redirect('contact')




here down urls.py

path("contact", views.contact, name="contact"),

then my form html


 <form action="{% url 'contact' %}" method="post" role="form" class=
"php-email-form" data-aos="fade-left">
              {% csrf_token %}
              <div class="form-row">
                <div class="col-md-6 form-group">
                  <input type="text" name="name" class="form-control" id=
"name" placeholder="Your Name" data-rule="minlen:4" data-msg=
"Please enter at least 4 chars" />
                  <div class="validate"></div>
                </div>
                <div class="col-md-6 form-group">
                  <input type="email" class="form-control" name="email" id=
"email" placeholder="Your Email" data-rule="email" data-msg=
"Please enter a valid email" />
                  <div class="validate"></div>
                </div>
              </div>
              <div class="form-group">
                <input type="text" class="form-control" name="subject" id=
"subject" placeholder="Subject" data-rule="minlen:4" data-msg=
"Please enter at least 8 chars of subject" />
                <div class="validate"></div>
              </div>
              <div class="form-group">
                <textarea class="form-control" name="message" rows="5"
data-rule="required" data-msg="Please write something for us" placeholder=
"Message"></textarea>
                <div class="validate"></div>
              </div>
              <div class="mb-3">
                {% for fmessage in messages %}
                <div class="error-message sent-message">{{fmessage}}</div>
                {% endfor %}
              </div>
              <div class="text-center"><button type="submit" class="send">
Send Message</button></div>
            </form>

          </div>

-- 
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/CAJCm56LAbJHrbNFworRZsuD-hP5Gok6wH%2BvQw1NgQuwAJ9_S4w%40mail.gmail.com.

Reply via email to