Hi
I have managed to write an application for checking POP3 and imap mailboxes, but I have a problem with HTML emails.
They include head tags which are messing up my page layout. It means that css is not inheritied by the content of the mail.
A second problem is that css within the message needs to be kept to allow text and other elements to display correctly, but at the same time some html emails sometimes have css that is applied to the body (such as backgrounds). This then gets applied to the whole page and obviously spoils the layout.
Has anyone encountered this before? I can't think of how to just remove css formatting that is applied to text/images/etc., but not the body, or to remove the whole head html but leave the necessary css.
Cheers
Fergus
Formatting HTML emails retrieved using imap
Moderator: General Moderators
for embedded styles maybe a pattern likethen you could add those values to your own header, maybe even prepend another element/class to prevent the elements of your page from beeing altered
(e.g. div { background-color: silver; }
div.mail div { background-color: silver; } )
(haven't tested this, only an idea)
Code: Select all
$pattern = '/([^\\s{}])\s*{([^}]*)}/';
preg_match_all($pattern, $styleElement, $matches);(e.g. div { background-color: silver; }
(haven't tested this, only an idea)
Found this on the web which appears to do the job:
Thanks for your help, volka. Much appreciated.
Fergus
Code: Select all
$toBeRemovedArray = array (
"'<html>'si",
"'</html>'si",
"'<bodyї^>]*>'si",
"'</body>'si",
"'<headї^>]*>.*?</head>'si",
"'<styleї^>]*>.*?</style>'si",
"'<scriptї^>]*>.*?</script>'si",
"'<objectї^>]*>.*?</object>'si",
"'<embedї^>]*>.*?</embed>'si",
"'<appletї^>]*>.*?</applet>'si",
);
$body = preg_replace($toBeRemovedArray, '', $body);Thanks for your help, volka. Much appreciated.
Fergus