ajguk
ajguk

Reputation: 171

HTML email from PHP - apostrophe problem

I have a webform in php that sends 2 emails. One is in plaintext, one in html to the customer that includes a url string based on the user input.

If the name field for instance says "Bob O'Reilly", the plaintext email is fine but the html email string would read "http://www.mysite.com?name=bob o", completely truncating the string. I know I need to escape the apostrophe but I've tried addslashes and it doesn't seem to do what I need it to.

Thanks

Upvotes: 0

Views: 628

Answers (1)

Pelshoff
Pelshoff

Reputation: 1464

You should probably urlencode the string when using it in a link: http://php.net/manual/en/function.urlencode.php.

This transforms any characters that may have some special meaning to a code like %20 (space). You can use urldecode if you need to accept a requested, urlencoded string.

Upvotes: 4

Related Questions