开发者

html email problem with posted php variable

开发者 https://www.devze.com 2022-12-12 23:20 出处:网络
I am working to send email w开发者_运维百科ith the html body. Body html is posted by php variable with ajax. but all html will be ignored.

I am working to send email w开发者_运维百科ith 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...


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.


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


If (') be your problem means try

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号