我有以下PHP。在這裏,我創建一個表,循環訪問傳入數據的鍵和值,並將它們添加到行中。當接收到郵件,它是添加隨機空白/空格中聯樣式,例如:PHP foreach添加隨機空白/空白
看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 = '[email protected]';
$to = $_POST['email'];
$cc = '[email protected]';
$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();
}
你是如何得到與缺口的輸出?它工作與否? (例如,是否應用了邊框) –
我認爲問題不在該foreach內部......嘗試在生成數據輸出時打印(回顯)所有字符串,並與稍後打印的內容進行比較。 – dognose
在這段代碼之後,我敢打賭$ data_output發生了其他事情。 – 2012-11-14 13:23:36