tags:

views:

57

answers:

3

Hi

I am working to send email with the html body. Body html is posted by php variable with ajax. but all html will be ignored.

for example in email.php

HTML element

<textarea id="html" cols="20" name="TextArea1" rows="2">HTML code is here</textarea>

Javascript

var html = $("#html").val();
$.post("function.php", {  html: html }, function(data) {

    if(data){
    //do sth

     }
     });

and in function php

$body = "";
    $body .= $_POST['html'];

  //send email

I tried html_entity_decode but no luck. the email is sent, comes without html elements. how can i do this ?

Thanks

EDIT: I got the problem, in HTML there is ' character and it disrupts the HTML structure.

But how can i avoid this, i still don't know...

EDIT 2 : stripslashes() made it ! Thanks...

A: 

I would get firebug and try to walk the process through in the browser & watch what exactly you are passing along to the php page. You may find that you're not posting anything. I imagine if PHP got it it should be at least be able to print it out for you as an echo.

Israel Lopez
i did it, it is passing HTML code perfectly. but when it sends email, only text appears without HTML elements (tables,cells etc..) in the email...
Ahmet vardar
A: 

What does the email sending code look like? To send HTML you need to include additional headers, see example #4 in the php docs: http://php.net/manual/en/function.mail.php

pygorex1
i use phpmailer, and all settings are ok for html email, it should be about variables, dunno :S
Ahmet vardar
A: 

Hi If (') be your problem means try

 $layout = addslashes($_POST['html']);

It will add backslash like (\') to the values.

RSK
thx, stripslashes() is the thing make it works...
Ahmet vardar