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="\"70\"" height="\"87\"" alt="\"d_6928_antiqueoak_vapor\"">
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
Post a Comment