1

I'm sending this HTML with the PHP mail() function:

    <div>hello<div><br></div><div>dsfs</div><div><b style="background-color:rgb(255,0,0)">dfs</b></div><div><b style="background-color:rgb(255,0,0)">df</b></div><div><b style="background-color:rgb(255,0,0)">sdf</b></div><div>sdf</div>
<div>sdfff</div></div>

It's a really simple HTML email, but Gmail shows this:

hello
dfs
df
<= div style=3D"color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13p= x;background-color:rgb(255,255,255)"> sdf
sdf
sdfff

Why is Gmail truncating my HTML and how can I fix it?

i'm directly catching the html code what was sent from gmail file_get_contents("php://stdin"); and processing this to extract the html code (i only remove the headers), therefore the html is perfectly correct and i don't must edit this. then, why if gmail send the html to another gmail this looks good but else i send the html this is a html disaster?

seriously, the html is perfectly according gmail

fj123x
  • 6,904
  • 12
  • 46
  • 58
  • You will never be happy with the results of your HTML output in any email client. They are designed to eliminate any possibly malicious code. I recommend using an email testing platform such as *litmus* or *email on acid*. – Matt Aug 06 '12 at 17:44
  • Also, are you using the `email()` function or the `mail()` function? – Matt Aug 06 '12 at 17:45
  • If you are using `
    `s you have to render your message in some way before including in the email body, other wise you will have to use normal text with only `
    `, `

    ` and that sort of tags on. Probably you can try to use a `

    ` in your email
    – mithilatw Aug 06 '12 at 17:46
  • Perhaps off topic, but you really need to choose a better naming convention for your filler text. For example, it would be far easier to understand what's going on with the basic Line 1, Line 2... Line 6; not the dsfs dsf sdfs used, which really strains the mind to follow. – Moses Aug 06 '12 at 17:49
  • I've seen this `style=3D"` thing before but I can't remember where... Check this out maybe: http://stackoverflow.com/questions/4016067/whats-a-3d-doing-in-this-html – Wesley Murch Aug 06 '12 at 18:01

1 Answers1

1

This is what your code should look like with proper formatting. I have moved your inline styles to the <div> since I'm not 100% certain how valid it is within a <b> tag.

<div>hello 
    <div><br /></div>
    <div>dsfs</div>
    <div style="background-color:rgb(255,0,0)"><b>dfs</b></div>
    <div style="background-color:rgb(255,0,0)"><b>df</b></div>
    <div style="background-color:rgb(255,0,0)"><b>sdf</b></div>
    <div>sdf</div>
    <div>sdfff</div>
</div>

Nothing is being truncated. <div> tags always display below one another unless the float or display:inline styles are set.

Matt
  • 6,993
  • 4
  • 29
  • 50
  • this is a valid html, if i send formated mail from gmail to my postfix server, the html is shown exactly how i published here. – fj123x Aug 06 '12 at 17:50
  • On second look, you're right. I misread your tags. Try my updated code and see if it helps. – Matt Aug 06 '12 at 17:56
  • Why would `background` or `style` not be valid on a `b` tag? – Wesley Murch Aug 06 '12 at 17:59
  • @Wesley Not sure, but email clients have a habit of doing some really wacky things. – Matt Aug 06 '12 at 18:00
  • i'm directly catching the html code what was sent from gmail file_get_contents("php://stdin"); and processing this to extract the html code (i only remove the headers), therefore the html is perfectly correct and i don't must edit this. then, why if gmail send the html to another gmail this looks good but else i send the html this is a html disaster? – fj123x Aug 06 '12 at 18:05
  • Your problem likely lies in `get_file_contents()`. I cannot know for sure what the problem is, but if forwarding the email from one gmail account to another creates no problems, it has to be some sort of processing that is done within `get_file_contents()`. – Matt Aug 06 '12 at 18:07
  • What does a source-code inspection show you when viewing the email through the client? (F12 in Chrome, or you can right-click and select *inspect element*) – Matt Aug 06 '12 at 18:08
  • the gmail splits the html like lines hi is splited as hi wtf gmail splits the html? – fj123x Aug 06 '12 at 18:12
  • Your problem has **nothing** to do with gmail. It lies in `get_file_contents()`. Find out why it would convert characters and you'll find your solution. – Matt Aug 06 '12 at 18:15