简体   繁体   中英

How can I pass text with & symbol from ajax to php code?

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>\n";
strVar += "<body>\n";
strVar += "\n";
------
------
strVar += "<div>\n";
strVar += "<center>Customer Name & Address<br><\/center>\n";
strVar += "<\/div>\n";
strVar += "<\/body>\n";
strVar += "<\/html>\n";
strVar += "\n";

        $.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?!?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM