WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

IT Discussion Forum Having IT issues? Got IT questions? Who doesn't? If you can't get your Apache to work with your MySQL or your php is choking on your ODBC... Let's see if we can help you come up with some ideas.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008, 08:32 PM
gr8dane gr8dane is offline
WebProWorld New Member
 

Join Date: Sep 2007
Location: Illinois
Posts: 3
gr8dane RepRank 0
Default (PHP) HTML entities in emails

I'm using values entered in a form to send an email using the mail() function. When the form is posted, I apply the htmlspecialchars() function to the values. The problem comes when I send the email: The HTML entities don't get translated in the email. I've considered decoding the values before I use them in the email, but wouldn't that open me up to the security problems the encoding was meant to avoid?
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 05:51 PM
mono mono is offline
WebProWorld New Member
 

Join Date: May 2006
Posts: 21
mono RepRank 0
Default Re: (PHP) HTML entities in emails

You need to analyze the html entities that are getting sent to you and determine whether you want to place them in emails that go out as yours. For example, scripts, probably not. HTML tags... do you really want arbitrary ones in your emails? Personally I strip all tags. What sort of html things would you want to preserve?
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 07:29 PM
gr8dane gr8dane is offline
WebProWorld New Member
 

Join Date: Sep 2007
Location: Illinois
Posts: 3
gr8dane RepRank 0
Default Re: (PHP) HTML entities in emails

I strip all tags, too. The problem is that my emails are getting sent as text, not HTML, so that an apostrophe, for example, that's been transformed into an entity doesn't get translated back into an apostrophe in the message.

I'm just starting to learn about how to make emails secure, so I'm not very clear about what kinds of malicious content might get sent through a form that could cause problems in an email. Would decoding the entities with htmlspecialchars_decode() make my emails vulnerable?
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 07:54 PM
httpman's Avatar
httpman httpman is offline
WebProWorld Pro
 

Join Date: Aug 2003
Location: France
Posts: 193
httpman RepRank 0
Default Re: (PHP) HTML entities in emails

To translate those entities in their html counterpart, you must send the email as a HTML email, not a TEXT. With PHP mail() function, this is done using the 4th parameter ($more below) :

mail($to,$subject,$mess,$more)

this 4th parameter is used to add any standard e-mail header information, for instance :

$more="From: xxxxxx\n"
."Cc: yyyyyy\n"
. "Bcc: zzzzzz\n"
. "Content-Type: text/html; charset=\"iso-8859-1\"\n";

xxxx, yyy and zzzzz stands for email addresses.
The "content-type" is set to text/html, this will force the email to HTML, and any special hml tag or specialchar will be translated. For instance if you place a <b>xxx</b> in your message, it will appear as xxxx in bold.

The charset depends of the set you are using in your email. 8859-1 is used in Europe, it supports our special characters with those little accents above.

JP
__________________
www.net-createurs.com [ french only website sorry ! ]
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 03:51 AM
youds youds is offline
WebProWorld New Member
 

Join Date: Dec 2007
Posts: 20
youds RepRank 0
Default Re: (PHP) HTML entities in emails

Read this!!!!
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) - Joel on Software

You have control over all areas of sending this email, is the character encoding the same in your web site as in your email???
Really, you shouldn't need any special functions like that, unless you want to convert & to &amp;.
Those functions are intended for when you don't have control over the input/output encodings!!!!!
__________________
http://www.youds.com
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 05:58 AM
crossland crossland is offline
WebProWorld New Member
 

Join Date: Jul 2007
Posts: 18
crossland RepRank 0
Default Re: (PHP) HTML entities in emails

You might want to look at some of the email packages that are available for PHP.
They make this sort of thing alot easier. One example is the Pear email package for PHP.

Hope this helps,

Tim
WebSphere MQ 7
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 08:19 AM
Faglork's Avatar
Faglork Faglork is offline
WebProWorld Veteran
 

Join Date: Feb 2005
Location: Forchheim, Germany
Posts: 945
Faglork RepRank 0
Default Re: (PHP) HTML entities in emails

Quote:
Originally Posted by youds View Post
Really, you shouldn't need any special functions like that, unless you want to convert & to &amp;.
Those functions are intended for when you don't have control over the input/output encodings!!!!!
Yep.

I ran into the same problem when switching my sites from ISO to UTF-8 (unicode).

Simplest solution: Use a UTF-8 capable mail prog, like NMS' TFMail. You can download it here:
nms - web programs written by experts

It has some other nice features as well, and is currently my preferred formmail solution.

hth,
Alex
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Validator is a Mozilla extension that adds HTML validat dougadam Graphics & Design Discussion Forum 3 02-10-2007 07:45 PM
How can I send HTML Emails? ackerley1 Marketing Strategies Discussion Forum 9 05-06-2006 01:27 PM
Newsletter software with HTML and CSS emails leonievs Graphics & Design Discussion Forum 5 03-02-2006 05:03 PM
Daily HTML emails JUNK! incrediblehelp WebProWorld: Guidelines/Announcements/Suggestions 15 07-20-2005 02:09 PM
PHP mailer that sends html emails IT-guy Web Programming Discussion Forum 7 06-09-2004 06:13 PM


Search Engine Friendly URLs by vBSEO 3.0.0