Home > front end >  how can i get mail from from_mail in django?
how can i get mail from from_mail in django?

Time:12-06

I am sending mail from my django site. Everything is fine and mail is also sent and received successfully, but not from_email(that put on email field in contact form). Email sent from EMAIL_HOST_USER = '[email protected]' that I put on setting.py.

def contact(request):
    if request.method == 'POST':
        name = request.POST['name']
        email = request.POST['email']
        subject = request.POST['subject']
        phone = request.POST['phone']
        message = request.POST['message']
        try:
            send_mail(subject,message,email,['[email protected]',],fail_silently=False)
            messages.success(request, 'We get your message and reply shortly...')
        except:
            messages.error(request, "failed")

    return render(request, 'pages/contact.html')

I want mail will be sent from email(that user put on the email field)

CodePudding user response:

you have to provide your email address instead of passing email of user who put in contact form so change your code like this

send_mail(subject,message,'[email protected]',['[email protected]',],fail_silently=False)

check official doc.

CodePudding user response:

Try this:-

def contact(request):
    if request.method == 'POST':
        name = request.POST['name']
        sender = request.POST['email']
        subject = request.POST['subject']
        phone = request.POST['phone']
        message = request.POST['message']
        try:
            msg_mail = str(message)" "   str(sender)
            send_mail(subject , msg_mail,sender ,  ['[email protected]'], fail_silently=False)
            messages.success(request, 'We get your message and reply shortly...')
        except:
            messages.error(request, "failed")

    return render(request, 'pages/contact.html')
  • Related