have you tried replacing
cd['message'],
with
cd['message']+cd['email'],
or
cd['message']+' your mail address is '+cd['email'],


Alan.


On May 18, 1:19 pm, Catalyst <cataly...@gmail.com> wrote:
>  I followed the instructions here to build a contact 
> form:http://www.djangobook.com/en/2.0/chapter07/
>
>  This works great, except I want to add the user's email address into
> the message body of the email that's sent through. In other words...
>
>   To: [Site Owner's Email]
>   From: [User's Email]
>   Subject: [Subject]
>   Message: [Message Body] [User's Email]
>
>   Anyone know an easy way to do this? Here's my views and forms .py
> files.
>
> # views.py
>
> from django.core.mail import send_mail
> from django.http import HttpResponseRedirect
> from django.shortcuts import render_to_response
> from myproject.forms.forms import ContactForm
>
> def contact(request):
>     if request.method == 'POST':
>         form = ContactForm(request.POST)
>         if form.is_valid():
>             cd = form.cleaned_data
>             send_mail(
>                 cd['subject'],
>                 cd['message'],
>                 cd.get('email', 'u...@example.com'),
>                 ['siteow...@example.com'],
>             )
>             return HttpResponseRedirect('/contact/thanks/')
>     else:
>         form = ContactForm()
>     return render_to_response('forms/contact.html', {'form': form})
>
> # forms.py
>
> from django import forms
>
> class ContactForm(forms.Form):
>     subject = forms.CharField()
>     email = forms.EmailField(required=False)
>     message = forms.CharField(widget=forms.Textarea)
>
> # End of code examples
>
>   In my views file, I thought I could do something simple like:
>
>   cd['message', 'email'],
>
>   But this gave me an error. Anyone know how I could pull this off?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to