【发布时间】:2015-06-12 20:48:03
【问题描述】:
我正在生成一封电子邮件,我注意到我的一些内联 CSS 样式显示不正确。经过进一步调查,我的输出似乎在整个字符串中随机换行。这是发生换行符的PHP部分
<?php
$message .= '<ul style="list-style:none">';
foreach ($fileLinks as $key => $value)
{
$message .= '<li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="' . $value . '">Download ' . $fileNames[$key] . '</a></li>';
}
$message .= '</ul>';
?>
我觉得这一切都很好
字符串中断并进入新行的输出示例会弄乱我的内联 css(我添加了行号以使其更易于阅读):
1. <ul style="list-style:none">
2. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-
3. bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L2JnLmpwZw==">Download bg.jpg</a></li>
4. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMS5qcGc=">Download slide1.jpg</a></li>
5. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMS5wZGY=">Download slide1.pdf</a></li>
6. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMi5qcGc=">Downlo
7. ad slide2.jpg</a></li>
8. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMi5wZGY=">Download slide2.pdf</a></li>
9. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMy5qcGc=">Download slide3.jpg</a></li>
10. <li><a style="font-family:sans-serif;background:#1F6FA9;color:#fff;padding:5px;text-decoration:none;border-radius:3px;margin-bottom:10px;display:inline-block;" href="http://myserver.com/file-transfer/download.php?i=Li4vdXBsb2Fkcy8wNi0xMi0yMDE1L3NsaWRlMy5wZGY=">Download slide3.pdf</a></li>
11. </ul>
我找不到任何关于换行位置或原因的一致性。有任何想法吗?它在第 2-3 行和第 6-7 行之间中断。
这是我的标题和send,以防您需要参考
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: file-transfer@myserver.com <file-transfer@myserver.com>' . "\r\n";
$headers .= 'Reply-To: '. $request->email . "\r\n";
$send = @mail('me@gmail.com', 'New Files from Secure File Transfer', $message, $headers);
?>
我尝试做一个 preg_replace 来删除任何 \n 或 \r
【问题讨论】:
-
我不知道确切的原因,但是您可以尝试在样式属性中添加空格,例如在每个分号之后添加空格吗?它认为它是一个长而不间断的词这一事实可能是原因。
-
@GolezTrol 刚刚尝试过,但没有运气。我被这件事难住了!
-
@Ronnie 线路什么时候搞砸了?如果您在 foreach 循环之后立即打印它们,或者如果您收到电子邮件?
-
@Rizier123 他们在电子邮件中换行。 gmail 和 Thunderbird 就是这种情况。 2-3 和 6-7 是无缘无故断线的地方
-
@Ronnie 但是,如果您在发送电子邮件之前打印它,一切都很好,对吧?
标签: php