-1
在下面的代碼中,每當按鈕被點擊時,sendmail函數被調用,並向php頁面發出ajax post請求。php intern發送郵件。我通過ajax函數以文本格式發送內容而不是瀏覽器上顯示的原始html格式。如何獲取郵件的內容爲html格式。如何使郵件的內容爲html格式而不是文本字符串?
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發送郵件 process.php
<?php
$var1=$_POST['div_content'];
$var2=fopen("somefile.txt","w+");
mail("[email protected]","My subject",$var1);//How to make the content in the html format rather than a string of text
fwrite($var2,$var1);
?>
我做this.But問題是$ _ POST [「div_content」]將返回文本,而不是HTML content.How使AJAX功能將內容發送到服務器以HTML格式,因爲數據類型:'應用程序/ html'不工作? – Volcanus