In the below code whenever the button is clicked sendmail function is called and makes a ajax post request to the php page.The php intern sends the mail.I am getting the contents sent by the ajax function in the text format rather than the original html format displayed on the browser.How to get the contents of the mail to be in the html format.
function sendmail(){
$.ajax({
dataType: 'application/html',
type: 'POST',url: 'process.php',
data: { 'number': $('#div_content').html() }//div_content has all the content displayed on the html page
}).done(function() {
$('#div_content').html( "Mail Sent" );
});
}
PHP for sending the mail
process.php
<?php
$var1=$_POST['div_content'];
$var2=fopen("somefile.txt","w+");
mail("example@gmail.com","My subject",$var1);//How to make the content in the html format rather than a string of text
fwrite($var2,$var1);
?>