0

I am making a contact form in JS using SMTP. but getting error HTTP 405. IDK what's the problem.

HTML

<div class="form-area">
                   <form class="form-submit-js" method="POST">
                       <input class="form name" type="text" placeholder="Name" ><br>
                       <input class="form email" type="email" placeholder="Email" ><br>
                       <textarea class="form message" type="text" placeholder="Message" rows="4"></textarea><br>
                       <input type="submit" class="contact-submit-button" onclick="sendEmail()" value="Submit"/>
                   </form>
               </div>

JS

function sendEmail() {
        Email.send({
        Host: "smtp.gmail.com",
        Username : "8083ankit@gmail.com",
        Password : "peuofkkuiqapazlq",
        To : '8083ankit@gmail.com',
        From : "8083ankit@gmail.com",
        Subject : "sent a message on your Portfolio",
        Body : "<email body>",
        }).then(
            (message)=>alert("mail sent successfully")
        );
        }

Please help me out

  • what is the server response ? check network tab in browser and put server response here – Mohammad Masoudi Apr 08 '21 at 18:03
  • and a note use SecureToken (you can create it from smptJS.com), if you use this code on your project everybody can see your email password it's not safe. – Mohammad Masoudi Apr 08 '21 at 18:05
  • @Iusifer, the *405* is a server side code, probably not JS [wiki:List of HTTP status codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) where: `405 Method Not Allowed`. The same question answered [#7381150/how to send an email from javascript](https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript) – azbarcea Apr 08 '21 at 19:03
  • Does this answer your question? [How to send an email from JavaScript](https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript) – azbarcea Apr 08 '21 at 19:05

1 Answers1

0

I just solved this issue and it seems the solution is dont use form I just use the div instead its maybe related to the request method and to grab the message just use let message = document.querySelector('.message').value;

Yuuta
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 17 '23 at 01:17