如何将带有&符号的文本从ajax传递给php代码?

如何将带有&符号的文本从ajax传递给php代码?

问题描述:

I am new to php and I am doing a billing software, my problem "When they billing a mail will send to a specific email address", email is working perfectly. When I pass the symbol & , the mail was sent but after the & symbol text were gone. I need to use some words like "customer Name & Address" in first word I receive the text only customer Name remaining & Address was missing. How can I solve this problem?

var strVar="";
strVar += "<html>
";
strVar += "<body>
";
strVar += "
";
------
------
strVar += "<div>
";
strVar += "<center>Customer Name & Address<br><\/center>
";
strVar += "<\/div>
";
strVar += "<\/body>
";
strVar += "<\/html>
";
strVar += "
";

        $.ajax({
            async: false,
            url: "sendmail.php",
            data: "htmldata="+strVar ,
            type: "POST",
            success: function(resp) {
                debugger;

                alert("Message Sent Successfully");

            },
            error: function(e) {
                console.dir("Contact Administrator");
            }
        });

In server side I am using normail PHPMailer concept.

Consider this small but important change:

data: {
    htmldata: strVar
}

That will take care that your data is encoded correctly inside your post.

Apart from that: why would you want to create html on the client side and send it to the server?!?