开发者

Sending HTML mail through PHP - strange rendering

开发者 https://www.devze.com 2023-01-22 07:28 出处:网络
I have a simple table: <table cellpadding=\"0\" cellspacing=\"0\" style=\"width:600px\"> <tr>

I have a simple table:

<table cellpadding="0" cellspacing="0" style="width:600px">
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">E-mail</td>
    开发者_如何学JAVA<td style="width:500px; padding:5px; border:1px solid #444">ex@ex.com</td>
  </tr>
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">Message</td>
    <td style="width:500px; padding:5px; border:1px solid #444">sometext</td>
  </tr>
</table>

When I test it, it looks fine:

Sending HTML mail through PHP - strange rendering

When I send it through PHP mail() function, it looks like this:

Sending HTML mail through PHP - strange rendering

Why is that margin there?

Just in case, my mail() headers are:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


The width of your table is 600px.

The width of the cells adds up as follows:

First cell: 1px border + 5px padding + 100px width + 5px padding + 1px border = 112px Second cell 1px border + 5px padding + 500px width + 5px padding + 1px border = 512px

Total width: 624px in a 600px width table.

This may not be the problem, but I bet it is not helping.

I suggest you correct this first and then see what happens.


did you by any chance insert \n\r between the rows in mail()?


Well, figured it out - the problem was that I did nl2br($message) before sending. ($message contains the above HTML code)

But thank you all for participation!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号