When to use rawurlencode() in PHP

I am compelled to write this to save many hours of frustration any other developer might be facing:

If you are trying to set email body using mailto: link dynamically, then naturally your first tendency is to use urlencode() to make the content compatible right?

But there’s a problem that email clients don’t understand the encoding produced by urlencode() since it produces encoding which is compatible for URLs not emails. So what do you do now?

Enter rawurlencode() which is you savior in this sticky situation!

rawurlencode() converts your string according to RFC 3986 which also means that you can use it to encode your dynamic content into the body of mailto: links!

Hope this helps somebody!

Advertisements

2 thoughts on “When to use rawurlencode() in PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s