0

Is it possible to send an email using JS, like PHP's mail() function.

I know you can use mailto in the action, like this:

<form action="mailto:example@example.com">
  <p>Type In Your Email</p>
  <input type="email">
  <input type="submit">
</form>  

But that just opens up the default email program. I want to send an email to the email they entered, from a different address.

Is there a way to send an email in JS, from a custom email address, without opening the default mail client?

Jacob G
  • 13,762
  • 3
  • 47
  • 67

4 Answers4

0

No. You can't send an email using HTML form action. You'll need to do it using server-side languages like PHP.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
0

Nop., with the help of only HTML you we can't send mail() because for sending emails we need to set server-side script so that server can send or receive requests

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
0

You can do it it javascript or jquery.

<form id="frm" action="mailto:example@example.com">
<p>Type In Your Email</p>
<input id="email" type="email">
<input id="btn" type="button">
</form> 

<script>

$(document).ready(function(){ 

 $('#btn').click(function(){ 

  $('#frm').attr('action', 'mailto:' + $('#email').val() ) ;
  $('#frm').submit();

 });

});

</script>
BarryDevSF
  • 395
  • 3
  • 12
-1

Yes, you can use python or ruby

...the title is misleading.

No, you'd have to use something in addition to JavaScript and html