[Answered ]-Send_mail() got multiple values for argument 'fail_silently' Django contact form only passing message not name or subject

1👍

A better way of doing it is to create HTML page for mail formatting. And pass all the data in that HTML page. This HTML format can be used as a message in send_mail ‘html_message’ field. Please check the below snippet for the same :

views.py:

def index(request):

   if request.method == 'POST':
       message = request.POST.get('message')
       name = request.POST.get('name')
       ctx = {
           'name' : name,
           'message' : message
       }
       message = render_to_string('mail.html', ctx)
       send_mail('Contact Form',
        message,
        settings.EMAIL_HOST_USER,
        ['myemail@gmail.com'], 
        fail_silently=False, html_message=message)
   return render(request, 'app/index.html')

mail.html :

<body>
  <h1>This is HTML page for mail</h1>
  <p>{{name}}</p>
  <p>{{message}}</p>
</body>

Leave a comment