5

I have a complex HTML form which I want to send via email. Is there a way to send and format the content of this email as HTML via javascript without using a server-side script?

Edit: Lets assume there is a smtp server at hand to do the job.

Thomas
  • 10,289
  • 13
  • 39
  • 55
  • You can't send an email from the client. – tbleckert Jun 11 '11 at 19:21
  • 1
    I don't think that this is possible. What you probably can do is use some 3rd-party service that provides the server-side logic to process the form and send the message. We do this with our own CMS that we sell to customers; all the HTML forms of all customers are being sent as e-mails through our central server. – Uwe Keim Jun 11 '11 at 19:21
  • Could it be done if I am using an exiting email account and its associated smtp server? – Thomas Jun 11 '11 at 20:01
  • 1
    No, because JavaScript will not allow you to connect to an external server on port 25, which is the port used to send email via SMTP. – Rob Raisch Jun 16 '11 at 20:49

3 Answers3

3

You can't send email from Javascript, so the obvious answer is no.

However, you can use the user's email client to send the email using the technique described in Sending emails with Javascript. Of course this allows the user opportunity to modify the email before it is sent, and it still requires an email server to accept the message, but it doesn't require you to write code that takes HTTP requests as input and sends email.

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806
1

in order to send an email you have to connect to an SMTP server, now this kind of connection you would like to make through the server for few reasons:

  1. you have no idea what kind of firewall does the client has, it might block your ports
  2. to make the client connect to your server you must supply him/it with a user name and password, a thing which you really don't want to do

other then that i do not know if there's a way to do this but i'll be rather surprised to hear of such a thing. good luck

Ido_f
  • 689
  • 1
  • 11
  • 29
  • is the smtp server remote or local? if remote you would not like to give clients the user name and password for after a short while it WILL be used for spam. you might also want to check connecting your application to outlook, i found this[link](http://www.tek-tips.com/viewthread.cfm?qid=1003014&page=1) which looks helpful – Ido_f Jun 11 '11 at 21:18
  • -1 since you cannot send email via JavaScript and so, doesn't answer the question. – Rob Raisch Jun 11 '11 at 23:35
  • i gave him alternatives to what he's looking for and explained why he's not trying the correct approach, what's the -1 for?? – Ido_f Jun 16 '11 at 19:49
  • @ldo_f, Because you cannot use JavaScript to connect directly to a SMTP server. A possible solution would be to submit the message to an HTTP server that would then submit the message to an MTA but that would violate the OP's requirement not to use a server-side script. – Rob Raisch Jun 16 '11 at 20:48
  • i didn't say he could use JS to connect to an SMTP server. all i did was to explain him why won't he want to the such thing, and showed him he could try connecting to outlook – Ido_f Jun 18 '11 at 17:48
0

Why not just publish the form on your website and send a link?

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83