How to send mail using django


So im trying to send a gmail in my django project. But every time i press the submit button i get html 405 error page.


def send_email(request):
    if request.method == "POST":
        name = request.POST.get("name")
        email = request.POST.get("email")
        message = request.POST.get("message")
        send_mail(name, email, message, [""])
        return HttpResponseRedirect("dashboard/")


<form action="" method="POST">
    {% csrf_token %}
    <input type="text" class="form-control" name="message_name" placeholder="Full name" id="full_name">
    <input type="text" class="form-control" name="message_email" placeholder="Email" id="login-email">
    <input type="text" class="form-control" name="message" placeholder="Poruka" id="text">
    <input type="submit" value="PoĊĦalji" class="login-button">


You forget to put actual URL to the action of the form. Then you send POST request to your current URL (which seems to not handle POST requests) and you justly receive 405 Method Not Allowed error.

Answered By – Yevgeniy Kosmak

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published