我有以下 PHP。在这里,我正在创建一个表,遍历传入数据的键和值,并将它们添加到行中。接收邮件时,它会在内联样式中添加随机间隙/空格,例如:
看bord er:4px solid #E4F5FD;
<td valign="top" style="padding:5px;border-collapse:collapse;bord er:4px solid #E4F5FD;text-transform:capitalize;font-family:arial;font-size:12px;background:#FFFFFF;">
和
看background:#FFF FFF;
padding:5px;border-collapse:collapse;border:4px solid #E4F5FD;text-transform:capitalize;font-family:arial;font-size:12px;background:#FFF FFF;color:#888888;
我不知道为什么会这样,以前有人遇到过这个问题吗?
请记住我正在学习 PHP,所以请善待。
$data_output .= '<table align="center" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;background:#E4F5FD;border:0;width:680px;">';
foreach ($data_html as $key => $value) {
$data_output .= '<tr>';
$data_output .= '<td valign="top" style="padding:5px;border-collapse:collapse;border:4px solid #E4F5FD;text-transform:capitalize;font-family:arial;font-size:12px;background:#FFFFFF;"><b>'.str_replace('_',' ',$key).'</b></td>';
$values = '';
foreach($value as $v) {
$values .= $v.'<br />';
}
$z = '';
if($values == ''){
$z = $value;
} else {
$z = $values;
}
$data_output .= '<td valign="top" style="padding:5px;border-collapse:collapse;border:4px solid #E4F5FD;text-transform:capitalize;font-family:arial;font-size:12px;background:#FFFFFF;color:#888888;">'.str_replace('_',' ',$z).'</td>';
$data_output .= '</tr>';
}
$data_output .= '</table>';
$from = 'website@bla.clo.uk';
$to = $_POST['email'];
$cc = 'me@bla.co.uk';
$subject = 'bla stuff';
$body = $data_output;
$headers = '';
$headers .= "From: $from\n";
$headers .= "Cc: $cc\r\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\n";
$headers .= "Date: " . date('r', time()) . "\n";
if (mail($to, $subject, $body, $headers)){
echo 'sent';
} else {
echo 'fail';
die();
}