toolman Posted October 24, 2012 Share Posted October 24, 2012 Hi, I am trying to validate a mailto link, but its not working. This is the code: mailto:[email protected]?subject=my subject here&body=this is the body Any ideas why it is not validating? Thanks Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/ Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 What do you mean "validate" it? Normally URLs must be run through urlencode(), but first you have to tell us what you mean by validate. Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387464 Share on other sites More sharing options...
toolman Posted October 24, 2012 Author Share Posted October 24, 2012 When I run it through the WC3 validator, I get this error: Line 99, Column 199: general entity "body" not defined and no default entity Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387467 Share on other sites More sharing options...
Christian F. Posted October 24, 2012 Share Posted October 24, 2012 Ampersands needs to be encoded to their ISO-equivalents, as they're a special HTML character. If you have PHP code that generates this link, then you'll need to use htmlspecialchars () on it. Otherwise, manually escape them. Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387471 Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 Show the whole line of HTML source. Are there quotes around the href value? The ampersand should not be encoded, since the link needs to have it in order to work. Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387474 Share on other sites More sharing options...
kicken Posted October 24, 2012 Share Posted October 24, 2012 You're still technically supposed to encode the & inside urls. Browsers don't have any issues if you don't though. href="mailto:[email protected]?subject=my+subject+here&body=this+is+the+body" would be correct for the validator and with URL encoding. Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387478 Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 I could have sworn christian said urlencode, not htmlentities. Yes, htmlentities is "more valid." Link to comment https://forums.phpfreaks.com/topic/269860-body-not-validating-in-mailto/#findComment-1387480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.