[Fixed]-Issue on sending message from contact page โ€“ Django 1.6

1๐Ÿ‘

โœ…

You are not declaring the variable first_name, last_name anywhere.

The following code will help you.

    temp_contact=Contact.objects.create(
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'],
        email=form.cleaned_data['email'],
        message=form.cleaned_data['message'],
    )
    temp_contact.save()
    try:
       send_mail(temp_contact.first_name,temp_contact.last_name,temp_contact.email,temp_contact.message, ['kristian.koci@gmail.com'])
    except:
       ...

Edit:

The following code will help you send the right thing.

    temp_contact=Contact.objects.create(
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'],
        email=form.cleaned_data['email'],
        message=form.cleaned_data['message'],
    )
    temp_contact.save()
    try:
        email_subject = "Contact Registration - "+temp_contact.email
        email_content = "Name:"+temp_contact.first_name+" "+temp_contact.last_name+"\nContent:"+temp_contact.message
       send_mail(email_subject,email_content,temp_contact.email, ['kristian.koci@gmail.com'])
    except:
       ...
๐Ÿ‘คSiddharth Gupta

Leave a comment