Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Using gmail SMTP

When an email is sent using the contact form I created, it does not show the email entered into the form as the sender.

1 Answer

Kinda hard to tell what the problem is from that sentence - you need to share your code

Sorry about that, here is my code:

view.py

def contact(request):
    form = forms.ContactForm()
    if request.method == 'POST':
        form = forms.ContactForm(request.POST)
        if form.is_valid():
            send_mail(
                'Inquiry from {}'.format(form.cleaned_data['name']),
                form.cleaned_data['inquiry'],
                '{name} <{email}>'.format(**form.cleaned_data),
                ['myname@site.com'] 
            )
            return HttpResponseRedirect(reverse('contact'))
    return render(request, 'contact.html', {'form': form})

settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myname@site.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

When I check myname@site.com email account, after filling out the contact form, shows that i sent myself an email.