Answer the question
In order to leave comments, you need to log in
How to send a letter from any addressee in the form?
Tell me, please, how can I send letters from any addressee from the form?
settings:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '***'
EMAIL_HOST_PASSWORD = '***'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'Python ecommerce <***>'
BASE_URL = '127.0.0.1:8010'
class ContactForm(forms.Form):
subject = forms.CharField(widget=forms.TextInput(
attrs={
"class": "form-control",
"placeholder": "ФИО"
}
)
)
sender = forms.EmailField(widget=forms.EmailInput(
attrs={
"class": "form-control",
"placeholder": "Email"
}
)
)
message = forms.CharField(widget=forms.Textarea(
attrs={
'class': 'form-control',
"placeholder": "Оставьте свои данные для связи"
}
)
)
copy = forms.BooleanField(required = False)
def contactView(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
message = form.cleaned_data['message']
copy = form.cleaned_data['copy']
recipients = ['***']
if copy:
recipients.append(sender)
try:
send_mail(subject, message, sender, recipients)
except BadHeaderError: # Защита от уязвимости
return HttpResponse('Invalid header found')
return render(request, 'thanks/thanks.html')
else:
form = ContactForm()
return render(request, 'Rest/contact.html', {'form': form})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question