View Full Version : Can I change margins in HTML emails?

08-25-2011, 10:32 PM
I'm using PHP to compose an html email and I'd like to add the following css statement to control the p margin spacing when the recipient looks at the email:

<style type="text/css">p {margin:0; padding: 0;}</style>

Right now, the vertical spacing is too much and this css statement reduces it nicely.

I'm not sure where to insert this css statement into my php script that constructs the html email?

08-26-2011, 11:54 AM
Then why don't you post your code?

08-26-2011, 03:54 PM
My php script is a rather long file. This is a snippet of where I create the headers. When I view the sent email in my gmail account, I don't see any change in the vertical spacing of the <p tags.

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= '<style type="text/css">p {margin:0; padding: 0;}</style>' . "\r\n";

08-26-2011, 04:22 PM
Review these lists and articles for a possible problem facing you:



HTML email display will depend largely on which email client the message is being viewed in. Things that work perfectly in one place won't register AT ALL in others. For example, <style> tags themselves are not honored at all in gmail, whether they are in the head or the body of the message. Hotmail won't honor all margins.

Things are complex. It might be more beneficial for you to provide us with the generated HTML code that is being sent as email rather than giving us the PHP. That will help us to see any formatting issues that may be present in the final product, which is where your trouble really is.