I have a div in which it’s contents are generated by JavaScript. I was wondering if it is possible to email the contents of the div? Also is it possible in JavaScript or must it be done in PHP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t email directly from JavaScript in the browser. You need to send the information to a server side (eg. PHP) file.
You can do this using a
form, but then you need a form field.If it’s a
div, you should use JavaScript. You can send a request (using AJAX), or, if the information is short and non-sensitive, you can navigate to the PHP page that does the email sending and add the information to the URL string.Here is a very quick mock-up of the code. In reality, you should filter inputs and write clean code and whatnot.
Javascript:
where http://www.myDomain.com/email.php is the url of the php file and theData is a variable containing the content of the div.
PHP
$_GET[‘data’] is the content sent by the JavaScript above.
I have not included the JavaScript to get the div content into the variable theData