html - php mail 添加随机空格和 float 元素

标签 html css php

我对 php mail() 函数有一些奇怪的看法。 当我用 php 发送邮件时,它会随机添加空格,并且一些 float 元素不起作用。

这些是我的标题:

$headers     = 'From: ' . $website_naam . ' <' . $eigen_emailadres . '>' . PHP_EOL;
$headers    .= 'Reply-To: ' . $naam_verzender . ' <' . $email_verzender . '>' . PHP_EOL;
$headers    .= ($bcc_emailadres != '') ? 'Bcc: ' . $bcc_emailadres . PHP_EOL : '';
$headers    .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
$headers    .= 'X-Priority: Normal' . PHP_EOL;
$headers    .= 'MIME-Version: 1.0' . PHP_EOL;
$headers    .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;

这是我的信息:

$message  = '<html><body style="font-family:Open Sans; margin:0; padding:0; font-size:14px; color:#4a4a4a;">';
$message .= '<head>';
$message .= '<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600" rel="stylesheet" type="text/css">';
$message .= '</head>';
$message .= '<div style="width:930px; margin-top:30px; background-color:#fff;">';
$message .= '<div id="logo" style="width:395px; height:54px; float:left;"><a href="http://www.klumpers.nl"><img src="http://www.klumpers.nl/images/logo.png" alt="Klumpers Goud en Diamanthandel" /></a></div>';
$message .= '<div style="clear:both;"></div>';
$message .= '<div style="height:1px; width:930px; background-color:#e2e2e2; margin-top:15px;"></div>';
$message .= '<div style="width:410px; background-color:#f7f7f7; margin-top:20px; padding:20px; float:left;">';
$message .= '<p style="font-size:20px; font-weight:400; color:#4a4a4a; margin:0 0 15px 0;">Gouden sieraden en voorwerpen</p>';
$message .= '<p style="line-height:12px;">&nbsp;&nbsp;8 karaat 33,3% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.333,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">14 karaat 58,5% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.585,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">18 karaat 75,0% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.750,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">20 karaat 83,3% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.833,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">21 karaat 87,5% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.875,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">22 karaat 91,6% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.916,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">24 karaat 99,9% goud <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.999,2)).' per gram</span></p>';
$message .= '<p style="font-size:20px; font-weight:400; color:#4a4a4a; margin:15px 0 15px 0;">Zilveren sieraden en voorwerpen</p>';
$message .= '<p style="line-height:12px;">2e gehalte zilver 83,5% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_zilver * 0.80 * 0.835,2)).' per kilo</span></p>';
$message .= '<p style="line-height:12px;">1e gehalte zilver 92,5% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_zilver * 0.80 * 0.925,2)).' per kilo</span></p>';
$message .= '<p style="line-height:12px;">Zilveren gulden 72,0% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_zilver_gram * 0.80 * 0.720 * 6.475 / 1000,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">Zilveren rijksdaalder 72,0% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_zilver_gram * 0.80 * 0.720 * 15 / 1000,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">Zilveren tientje 72,0% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_zilver_gram * 0.80 * 0.720 * 25 / 1000,2)).' per stuk</span></p>';
$message .= '<p style="font-size:20px; font-weight:400; color:#4a4a4a; margin:15px 0 15px 0;">Officieel gestempelde edelmetaal baren</p>';
$message .= '<p style="line-height:12px;">Baren fijn goud 99,99% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["goud_koers"],2)).' per kilo</span></p>';
$message .= '<p style="line-height:12px;">Baren fijn zilver 99,9% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["zilver_koers"],2)).'  per kilo</span></p>';
$message .= '<p style="line-height:12px;">Baren fijn platina 99,5% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["platina_koers"],2)).' per kilo</span></p>';
$message .= '<p style="line-height:12px;">Baren fijn palladium 99,5% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["palladium_koers"],2)).' per kilo</span></p>';
$message .= '</div>';// einde linker box
$message .= '<div style="width:410px; background-color:#f7f7f7; margin-top:20px; padding:20px; float:right;">';
$message .= '<p style="font-size:20px; font-weight:400; color:#4a4a4a; margin:0 0 15px 0;">Gouden Munten</p>';
$message .= '<p style="line-height:12px;">Muntgoud 90,00% <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900,2)).' per gram</span></p>';
$message .= '<p style="line-height:12px;">Dukaat 3,49 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.983 * 3.49,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Frank Belgie 6,45 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 6.45,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Frank Frankrijk 6,45 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 6.45,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Frank Zwitserland 6,45 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 6.45,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Lire Italie 6,45 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 6.45,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">10 Gulden Nederland 6,72 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["goud_koers"] / 1000 * 0.92 * 0.900 * 6.72,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Mark Duitsland 7,96 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 7.96,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">Souvereign Engeland 7,99 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.916 * 7.99,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20 Kroner D-marken 8,96 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 8.96,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">100$ Canada 16,96 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.916 * 16.96,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">50 ECU Belgie 17,28 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 16.96,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">Maple Leaf Canada 31,10 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["goud_koers"] / 1000 * 0.96 * 0.999 * 31.1035,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">100$ Australie 31,10 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["goud_koers"] / 1000 * 0.96 * 0.999 * 31.1035,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">20$ USA 33,43 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 33.43,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">100 Corona Oosterijk 33,87 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 33.87,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">Krugerrand Zuid Afrika 33,93 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers["goud_koers"] / 1000 * 0.92 * 0.916 * 33.93,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">50$ USA 33,93 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.916 * 33.93,2)).' per stuk</span></p>';
$message .= '<p style="line-height:12px;">50 Pesos Mexico 41,67 gram <span style="float:right; margin-right:20px;">&#8364; '.sprintf("%01.2f",round($koers_goud * 0.900 * 41.67,2)).' per stuk</span></p>';
$message .= '</div>'; // einde rechter box
$message .= '<div style="clear:both;"></div>';
$message .= '</div>';// einde container
$message .= '</body></html>';

这会在 G-mail 客户端中输出:

enter image description here

其他电子邮件客户端更糟糕。

最佳答案

不是 mail 函数把事情搞砸了。这是邮件客户端。不要依赖电子邮件中的 float 元素。电子邮件客户端对 HTML 和 CSS 的支持与浏览器不相上下。

您应该改用表格。至少他们是可靠的。

关于html - php mail 添加随机空格和 float 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16422843/

相关文章:

php - 从逗号分隔值 mysql 和数组中查找并选择

html - CSS 问题中心和 'max-width' 用于 IE11 中的图像

javascript - 使用 jquery 动态删除 Bootstrap 弹出窗口

html - 与 div 元素相比,图像变得不对齐,尽管有相同的 css

html - 将响应式 View 裁剪的图像居中

php - 如何制作 n :1 multiple tags system for a blog & which database schema is better?

jquery - Chrome 绝对定位

html - 如何转义 CSS 中的单引号或双引号?

jquery - 带或不带引号的属性选择器?

javascript - preg_match 不工作 php 和 javascript