Reputation: 9
what i have in 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 = 'pi**@gmail.com'
EMAIL_HOST_PASSWORD = '********'
what i have on forms.py
from django import forms
class contactEmail(forms.Form):
contact_name=forms.CharField(required=True)
contact_email=forms.EmailField(required=True)
subject=forms.CharField(required=True)
contact_message=forms.CharField(widget=forms.Textarea,required=True)
what i have on views.py
from django.shortcuts import render
from Myportfolio.forms import contactEmail
from django.core.mail import send_mail
from django.conf import settings
def contact(request):
if request.method=='GET':
form=contactEmail()
else:
form=contactEmail(request.POST)
if form.is_valid():
name=form.cleaned_data['contact_name']
subject = form.cleaned_data['contact_subject']
email=form.cleaned_data['contact_email']
message=form.cleaned_data['contact_message']
send_mail(name, subject, email, message, ['[email protected]', email])
return render(request, 'Myportfolio/contact-me.html', {'form': form})
What I have on contact-me.html
<form method="post" class="breakable contactUsForm "
data-thanks-msg="Thank you for contacting me, I have received your message and I will come back to you shortly"
data-date-format="m/d/Y" data-click-action="">
{% csrf_token %}
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input type="text" name="contact_email" placeholder="From Email address"
class="form-control s123-force-ltr" data-rule-email="true"
data-msg-email="Please enter a valid email." required
data-msg-required="This field is required.">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="text" name="contact_subject" placeholder="Subject" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="contact_name" placeholder="name" class="form-control" required
data-msg-required="This field is required.">
</div>
<div class="form-group">
<textarea class="form-control" name="contact_message" placeholder="Message" style="min-height: 100px;"
required data-msg-required="This field is required."></textarea>
</div>
<button type="submit" class="btn btn-primary btn-block">Contact Me</button>
</div>
<input type="hidden" name="w" value="">
<input type="hidden" name="websiteID" value="3438192">
<input type="hidden" name="moduleID" value="56f3eb72d83fa">
<input type="hidden" name="layout" value="7">
<input type="hidden" name="recaptchaToken" value="">
</form>
Please assist, i want people to be able to put in their details incase they want to be intouch when they get to my website contact page and then those details to be sent to my email
Upvotes: 0
Views: 657
Reputation: 68
Please set the Gmail configuration to allow less secure app in Gmail security setting.
Upvotes: 1
Reputation: 2485
A user cannot send you an email via django unless he has enabled API access in his gmail settings.
A possible solution is to self-send you an email (via EMAIL_HOST_USER) containing the specifications entered by the user who contacts you (email, text of the message and more)
Upvotes: 0
Reputation: 72
is this website live? I know that AWS free tier doesn't allow smtp connections so you can't send email using Gmail. For me I use mailjet.
Upvotes: 0