I am trying to make a contact us form which will send a mail to me using the 
smtp server .It will load the thank you page after form submission 
.Everything is working something ,the thank you page is loading and i am not 
getting any errors ,but i am not getting the mails.

here is my views.py file.:
from django.shortcuts import render_to_response
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.template import RequestContext
def contacts(request):
    errors=[]
    if request.method=='POST':
        if not request.POST.get('subject',''):
            errors.append('Enter a subject')
        if not request.POST.get('email') and '@' not in 
request.POST['email']:
            errors.append('Enter a valid email address')
        if not errors:
            send_mail(
                request.POST['subject'],
                request.POST['message'],
                request.POST.get('email','mehrotra.pul...@gmail.com'),
                ['mehrotra.pul...@gmail.com'],
            )
            return HttpResponseRedirect('/contact/thankyou/')
    return render_to_response('form.html',{
        'errors':errors,
        'subject':request.POST.get('subject',''),
        'email':request.POST.get('email',''),
        },context_instance=RequestContext(request))

def thankyou(request):
    return render_to_response('thankyou.html')

here is my form.html:

<html>
<head>
    <title>Contact Us </title>
</head>
<body>
<h1>Contact us </h1>
    {% if errors %}
        <ul> {% for error in errors %}
            <li> {{ error }} </li>
              {% endfor %}
        </ul>
    {% endif %}
    
    <form action="/contact/" method="POST">    
    {% csrf_token %}
        <p>Subject:<input type="text" name="subject" value="{{ subject }}" 
></p>
        <p>Email :<input type="text"name="email" value="{{ email }}"></p>
        <p>Message :<textarea name="message" rows="10" columns="50" 
></textarea></p>
        <input type="submit" value="Submit">
    </form>
    </body>
    </html>     

and here is my thankyou.html:

<html>
<h1>thank you</h1>
</html>

i am using the postfix smtp server

any help would be appreciated,thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/cTl4LTcwblFiVzhK.
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