我有三个 php 页面。首先是一个 selection.php 页面,其中包含由复选框选择的选项。提交时,将显示选项和用于将结果发送到的电子邮件字段(可选)。问题在于电子邮件的格式。请参阅下面的代码、电子邮件结果和理想输出。我感谢任何人的帮助和时间!
选择.php
$sqlSAT1 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 1'";
$sqlSAT2 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 2'";
$sqlSAT3 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 3'";
mysql_query($sqlSAT1);
$result = mysql_query($sqlSAT1);
while($row = mysql_fetch_array($result))
{
echo "<ul><li>";
echo'<input type="checkbox" name="id[]" value="'.$row['id'].' " id="bandSched_' . $row['id'] . '" />';
echo '<label for="bandSched_' . $row['id'] . '">' . $row['timeShow']." ".$row['bandName'] . '</label>';
echo "</li></ul>";
}
?>
结果.php
<?php
if ( ! empty($_POST['id']))
{ foreach($_POST['id'] as $key => $id) { $_POST['id'][$key] = mysql_real_escape_string($_POST['id'][$key]); }
$in = implode(', ', $_POST['id']);
$sqlSAT1 = "SELECT * FROM bandSched WHERE day='saturday' AND stage='stage 1' AND id IN ($in) ORDER BY FIELD(id, $in)";
$result = mysql_query($sqlSAT1) or die('MySQL Error ' . mysql_errno() . ': ' . mysql_error());
}
if ( ! isset($result))
{
echo 'You did not select anything';
}
else
{
while ($row=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>". $row['timeShow'] ."</td><td>" . $row['bandName'] . "</td>";
echo "</tr>";
}
}
?>
和 EmailProcess.php
<?php
$to = $_POST["email"];
$subject = "This is subject";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From:abc@somedomain.com \r\n";
foreach($_POST as $key => $value){
if(!(!isset($value))){$set=1;}
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}
$retval = mail ($to,$subject,$message,$headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}?>
最后,这就是带有结果的实际电子邮件的样子——
divcontent:
<div class=\"saturdaySched full_width light_gray\">
<div style=\"padding:20px\">
<h2>SATURDAY</h2>
<div id=\"stage1sat\" class=\"stageBox\">
<h3>STAGE 1</h3>
<table>
<tbody><tr><td>11:30</td><td>G.Wizz</td></tr><tr><td>12:20</td><td>Sideshow Tramps</td></tr><tr><td>1:40</td><td>Clap Your Hands
Say Yeah</td></tr> </tbody></table>
</div>
<div id=\"stage2sat\" class=\"stageBox\">
<h3>STAGE 2</h3>
<table>
<tbody><tr><td>12:00</td><td>The Wheel Workers</td></tr><tr><td>2:20</td><td>Starfucker</td></tr><tr><td>3:40</td><td>Phantogram</td></tr>
理想的电子邮件格式可以像列表(或类似的东西)一样简单
Stage 1- band1 2:30
Stage 1- band5 3:30
Stage 2- band4 3:10
etc...