0

How to send an email automatically to the submitted form email using Javascript ?

Here is the HTML code : <form id="form" action="index.php" method="POST"> <div class="nometprenom"> <div class="uinput"> <input type="text" id="nm" class="inp" name="nom" required autocomplete="off" placeholder="Nom"/> </div> <div class="uinput"> <input type="text" id="prnm" class="inp" name="prenom" required autocomplete="off" placeholder="Prénom"/> </div> </div> <div class="uinput"> <input type="email" class="inp" name="email" required autocomplete="off" placeholder="E-mail"/> </div> <div class="uinput"> <input type="text" class="inp" name="promotion" required autocomplete="off" placeholder="Promotion"/> </div> <button type="submit" class="submit">Générer</button> </form> What I want to happen : When the client tap the submit button, an email will be sent automatically to the email submitted in the HTML form. Thanks.

28th Jun 2021, 10:36 AM
Abdelwadoud ACHOUCHE
Abdelwadoud ACHOUCHE - avatar
4 Antworten
+ 1
usually form data are submitted to server side: so best way is to handle email sending at server side... alternatively, you could use 'mailto' protocol in link src / form action attributes... but that only open a prefilled mail in the default mail client of user, wich must manually send it (so he can also modify it before, and/or decide to not send it)... also, to achieve that with javascript, you must intercept the form submission / link click, and fill the related attribute with the email address and eventually content: that's quite tricky, in addition to not be exactly what you expect as "automatically send" ;P
28th Jun 2021, 10:44 AM
visph
visph - avatar
+ 1
Thnx a lot bro !! What do you suggest to me ? using server side or using javascript.
28th Jun 2021, 10:59 AM
Abdelwadoud ACHOUCHE
Abdelwadoud ACHOUCHE - avatar
+ 1
as you seems to know how to use server side scripting (action="index.php" as form attribute), I would advise you to do it in your index.php file (server side) ^^
28th Jun 2021, 11:02 AM
visph
visph - avatar
+ 1
Thanks again bro ! I appreciate your help.
28th Jun 2021, 11:07 AM
Abdelwadoud ACHOUCHE
Abdelwadoud ACHOUCHE - avatar