javascript - Pass html variable from Ajax to PHP -


i trying use code pass via post variable containing html

var data = {     message: $('#mydiv').html() }; jquery.ajax({     type: 'post',     data: data,     url: '/myurl?action=send_email',     success: function( response ) { } }); 

in php, retrieve data , send email using data content

$message = "hello<br>" . $_post['message'] . "<br>bye bye"; $mail = mail($email, $subject, nl2br($message), $headers); 

the html within email receive badly formatted:

<img width="\&quot;70\&quot;" height="\&quot;87\&quot;" alt="\&quot;d_6928_antiqueoak_vapor\&quot;"> 

can tell me why , if there solution? thank lot

try method using encodeuricomponent()

var data = 'message='+$('#mydiv').html(); jquery.ajax({     type: 'post',     data: encodevars(data),     url: '/myurl?action=send_email',     success: function( response ) { } });   function encodevars(vars){     return vars.map(function (cell) {         var res = cell.split('=');         return res[0] + '=' + encodeuricomponent(res[1]);     }) ;     } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -