views:

45

answers:

4

Folks, I have a HTML file which contains a button called "Email this content to me". Upon pressing this button, I want the complete HTML content of the file to be emailed to me. Can someone tell me if there is a javascript function to do that. A short example would go a long way :)

Thanks in advance

+1  A: 

You can't email by Javascript alone. You need some server side technology that will process the HTML form and email it (using CGI, PHP, ASP.NET, JSP or any other server side technology).

Oded
A: 

Is the page dynamically generated? If so why not just insert this into the body of your mail?

If its not dynamically generated why not just insert the URL into the message section of the email.

Russell Dias
A: 

Short answer: No.

For an email to be sent you need a serverside system (ie. Python/Java/.net) to make the SMTP request an populate the email, set sender, subject and receiver.

You'll need some of this information to be added in a html form (http://en.wikipedia.org/wiki/Form_(web)) that is posted to a serverside code.

Use google to search for example for the current serverside system you use.

..fredrik

fredrik
A: 

As long as the user has a proper mailto: handler set up, and the user is willing to actually send the email itself then yes, it is possible:

function handlerForClickEvent() {
    var body = document.body.innerText; //no point in using innerHTML
    location.href = "mailto:[email protected]?subject=my%20subject&body="+ encodeURIComponent(body);
}

This will cause the default mail handler to be opened with a ready email containing the to:, subject: and body: fields.

All the user has to do is press [send].

Sean Kinsey
Thanks. I ended up using document.documentElement.innerHTML
Amarsh