我对php mail()函数有些奇怪。 当我用php发送邮件时,它会随机添加空格,而某些浮动元素不起作用。
这些是我的标题:
$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;"> 8 karaat 33,3% goud <span style="float:right; margin-right:20px;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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;">€ '.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客户端输出:
其他电子邮件客户端更糟糕。
答案 0 :(得分:5)
这不是mail
功能搞砸了。这是邮件客户端。不要依赖电子邮件中的浮动元素。电子邮件客户端的HTML和CSS支持与浏览器不同。
您应该使用表格。至少他们是可靠的。
答案 1 :(得分:0)
我同意Bart的观点,即CSS是邮件客户端的一个问题。但我有同样的问题,只使用列表简单的HTML,见下文:
<ol>
<li>{$orderID} is ouder dan 2 maand en niets betaald is geannuleerd!</li>
</ol>
这导致:
45645645 is ouder dan 2 maand en niets betaald is geannuleerd!
68867676 is ouder dan 2 maand en niets betaald is geannuleerd!
45678545 is ouder dan 2 maan d en niets betaald is geannuleerd!
45667845 is ouder dan 2 maand en niets betaald is geannuleerd!
97856745 is ouder dan 2 maand en niets betaald is geannuleerd!
第3行显示不应该存在的空间。有时,邮件中甚至包含HTML < li>
,但HTML标记内也添加了空格。当一切都变成了桌子时,同样的事情发生了。
对我来说,解决方案是在HTML中添加\n
。所以上面的代码改为:
<ol>\n
<li>{$orderID} is ouder dan 2 maand en niets betaald is geannuleerd!</li>\n
</ol>\n
现在这些空间已经消失了。所以不仅仅是CSS。不知道为什么\n
解决了这个问题,但它确实有效!