0

I was trying to make contact form for my website, its loading, working and submitting successfully but i'm not receiving any mail from my website. I also created a form like that for reset password its working but not this why? my html

<div class="blog_list">
<form method="POST">
    {% csrf_token %}
     <h2 class="blog_heading">Contact Us</h2>
    <fieldset class="form-group">
        {{ form|crispy}}
    </fieldset>
    <div class="form-group">
        <button class="btn btn-outline-info" type="submit">Submit</button>
    </div>
</form>

my views.py

def contact(request):
if request.method == 'GET':
    form = ContactForm()
else:
    form = ContactForm(request.POST)
    if form.is_valid():
        subject = form.cleaned_data['subject']
        from_email = form.cleaned_data['from_email']
        message = form.cleaned_data['message']
        messages.success(request,f'Message sent successfully!')
        return redirect('Love Travel-home')
        try:
            send_mail(subject, message, from_email, ['admin@example.com'])
        except BadHeaderError:
            return HttpResponse('Invalid header found.')
return render(request, "shop/contact.html", {'form': form})

my forms.py

class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea, required=True)

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS =True

EMAIL_HOST_USER = os.environ.get('django_user')
EMAIL_HOST_PASSWORD = os.environ.get('django_pass')

I made contact form it submits it successfully but i didn't receive mail, can anyone please help me?

Kanwarjeet Singh
  • 722
  • 1
  • 12
  • 34
  • Many email providers won't let you use another user's email for the from email. Change `from_email` to your email address, then set `reply_to` to the user's email. See [this answer](https://stackoverflow.com/a/9281548) for more info. – Alasdair Apr 22 '20 at 09:52
  • mean, form_email to my real email and where i set reply_to? – Kanwarjeet Singh Apr 22 '20 at 09:55
  • There's an example of how to use `reply_to` in the answer I linked to. – Alasdair Apr 22 '20 at 09:58

0 Answers0