Here’s the code. It works as I want it to, but not sure why the formatting is retained.
I have another question: why does the subject get mangled but the message body shows Japanese correctly? How can I get the subject to be properly formatted?
<html>
<head>
<title>Send email</title>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Type" content="text/javascript; UTF-8 ">
<link rel="shortcut icon" href="../../favicon.ico">
<link rel="icon" href="../../favicon.png" type="image/png">
<link rel="stylesheet" type="text/css" href="styles.css">
<style type="text/css">
td {
font-size: 14px;
padding:1;
}
@-webkit-keyframes blink {
50% { border-color: #ff0000; }
}
@keyframes blink {
50% { border-color: #ff0000; }
}
div#test {
padding: 1px;
border: 10px solid transparent;
}
#test:hover {
animation: blink .5s step-end infinite alternate;
-webkit-animation: blink .5s step-end infinite alternate;
}
</style>
<title>Selecting or deselecting all CheckBoxes</title>
<script type="text/javascript">
function selects(){
var ele=document.getElementsByClassName('checkbx');
for(var i=0; i<ele.length; i++){
if(ele[i].type=='checkbox')
ele[i].checked=true;
}
}
function deSelect(){
var ele=document.getElementsByClassName('checkbx');
for(var i=0; i<ele.length; i++){
if(ele[i].type=='checkbox')
ele[i].checked=false;
}
}
</script>
</head>
<!-- BODY -->
<body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" style="font-size:13px;">
<span style="z-index:100; position:absolute; left:10px; top:8px"><font style='color: orange; font-size:14px'>
<script language='javascript'>
document.write('<b>SEND EMAIL</b>');
</script>
</font></span>
<table width="100%" cellspacing="0" cellpadding="3" style="border:0;height:31px"><tr><td bgcolor="black" align=center style="border:0">
<input type="button" value="Return to main menu" onClick="window.location='../index.php';" class="button" />
</td></tr></table>
<!-- send message -->
<?php
if (isset($_POST['submit']) && $_POST['submit']=="SEND MESSAGE") { //b
$subject=$_POST['subject'];
$message=$_POST['message'];
$message=wordwrap($message,70);
$listofadds="";
foreach ($_POST['emailto'] as $send) { //d
include ('/home/usn/private/dblon.php');
$to=$send;
$headers = "From: info@company.com";
mb_language("ja");
$subject = mb_convert_encoding($subject, "ISO-2022-JP","AUTO");
$subject = mb_encode_mimeheader($subject);
$message = mb_convert_encoding($message, "ISO-2022-JP","AUTO");
$mail_sent = mail($to, $subject, $message, $headers );
echo ($mail_sent ? "<p><span style='color:#006400; font-weight:bold; font-size:16px;'> An email has been sent to ".$send. ".</span></p>" : "<p><span style='color:#AC0000; font-weight:bold;'>Mail could not be sent to ".$send.". Please try again later.</span></p>");
$listofadds="$listofadds"." $send\n";
} //d
$adminmessage="The message below has been sent to\n\n"."$listofadds"."\n\nSubject:\n\n$subject\n\nMessage:\n\n$message";
$headers = "From: info@company.com";
$mail_sent = @mail("info@company.com", "Mail sent to", $adminmessage, $headers );
echo ($mail_sent ? "<p><span style='color:#8B008B; font-weight:bold; font-size:16px;'><br> A copy has also been posted to admin.<br><br> Return to the <a href='../index.php' class='navylink'>Main Menu</a>.</span></p>" : "<p><span style='color:#AC0000; font-weight:bold;'>Mail could not be sent to admin.</span></p>");
exit();
} //b
?>
<!-- addresses submitted -->
<?php
if (isset($_POST['submit']) && $_POST['submit']=="COMPOSE MESSAGE" && isset($_POST['email'])) { //r
?>
<form name="compose" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table cellpadding="5" cellspacing="0" style="margin-top:20px;" align="center"><tr><td colspan="4" style="background-color:#DDA0DD; font-size:15px;">You chose the following email addresses to email.<br> Compose the message below and click 'SEND MESSAGE'. A copy will be sent to admin.<br>If the address list is incorrect click 'Cancel' to start again.</td></tr>
<tr style="color:navy; font-size:15px; font-weight:bold; background-color:#FFE4E1;"><td align="center">Stu #</td><td>Class</td><td>Name</td><td width="400">Send to</td></tr>
<?php
$emailto=array();
[$i]="";
foreach ($_POST['email'] as $sendto) { //h
echo("<input type='hidden' name='emailto[$i]' value='".$sendto."'>");
if($_POST['how']=="alpha") {
include ('/home/usn/private/dblon.php');
$result=mysqli_query($dbcnx, "SELECT stuno,fname,lname,emailhome,emailmobile,emailwork,day,starth,startm FROM Details WHERE emailhome='$sendto' OR emailmobile='$sendto' OR emailwork='$sendto'");
}
if($_POST['how']=="class") {
include ('/home/usn/private/dblon.php');
$result=mysqli_query($dbcnx, "SELECT stuno,fname,lname,emailhome,emailmobile,emailwork,day,starth,startm FROM Details WHERE (emailhome='$sendto' OR emailmobile='$sendto' OR emailwork='$sendto')");
}
while ($row=mysqli_fetch_array($result)) { //e
$stuno=$row['stuno'];
$fname=$row['fname'];
$lname=$row['lname'];
$emailhome=$row['emailhome'];
$emailmobile=$row['emailmobile'];
$emailwork=$row['emailwork'];
$day=$row['day'];
$starth=$row['starth'];
$startm=$row['startm'];
echo ("<tr><td style='text-align:center'>".$stuno."</td><td>".$day." (".$starth.":".$startm.")</td><td>".$fname." ".$lname."</td><td>");
if ($sendto==$emailhome) {echo("(Home) ");}
if ($sendto==$emailmobile) {echo("(Mobile) ");}
if ($sendto==$emailwork) {echo("(Work) ");}
echo($sendto."</td></tr>");
} //e
} //h
?>
<tr><td style="background-color:#898d8f; padding:8px;" colspan="4" align="center">
<input type="button" value="Cancel" onClick="window.location='sendemail.php';" >
<input type="button" value="Return to main menu" onClick="window.location='../index.php';">
</td></tr></table>
<table cellspacing="0" style="margin-top:20px; border:0" align="center">
<tr><td style="border:0;"> Subject <span style="font-size:13px;color:#994444;font-weight:bold">(in English):</span></td></tr>
<tr><td style="border:0;"><input type="text" name="subject" size="67"></td></tr>
<tr><td style="border:0;"> Message:</td></tr>
<tr><td style="border:0;">
<textarea name="message" rows="30" WRAP="hard" cols="65">
**このメールは送信専用です。返信いただく場合はinfo@company.comへお願いします**
_____________________________
Company
info@company.com
www.company.com
_____________________________
</textarea>
</td></tr>
<tr><td align="center" style="background-color:#898d8f;padding:8px;border:0"><input type="submit" name="submit" value="SEND MESSAGE" class="button">
<input type="reset" value="Clear Form"></td>
</tr>
</table>
</form>
<?php
exit();
} //r
?>
<!-- get names -->
<?php
if (isset($_POST['submit']) && $_POST['submit']=="COMPOSE MESSAGE" && !isset($_POST['email'])) { //k
$tryagain="1";
echo(" <span style='color:#AC0000; font-weight:bold; font-size:16px;'>No email addresses were chosen.</span>");
} //k
if ((isset($_POST['submit']) && $_POST['submit']=="GET LIST" && isset($_POST['howlist'])) OR isset($tryagain)) { //p
?>
<form name="form2" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table cellpadding="5" cellspacing="0" style="margin-top:20px;" align="center"><tr><td colspan="4" style="background-color:#DDA0DD; font-size:15px;"> Select ALL the student(s) and email address(es) you wish to send to <span style="color:#ac0000;font-weight:bold">(or Select All at the bottom):</span></td></tr>
<tr style="color:navy; font-size:15px; font-weight:bold; background-color:#FFE4E1;"><td align="center"> Stu # </td><td> Class </td><td> Name</td><td width="400"> Send to </td></tr>
<?php
include ('/home/usn/private/dblon.php');
if ($_POST['howlist']=="allabc") {
$result=mysqli_query($dbcnx, "SELECT stuno,fname,lname,emailhome,emailmobile,emailwork,day,starth,startm FROM Details ORDER BY fname");
echo("<input type='hidden' name='how' value='alpha'>");
}
if ($_POST['howlist']=="allclass") {
$result=mysqli_query($dbcnx, "SELECT stuno,fname,lname,emailhome,emailmobile,emailwork,day,starth,startm FROM Details ORDER BY day,starth,startm,fname");
echo("<input type='hidden' name='how' value='class'>");
}
$email=array();
$count=0;
while ($row=mysqli_fetch_array($result)) { //j
$stuno=$row['stuno'];
$fname=$row['fname'];
$lname=$row['lname'];
$emailhome=$row['emailhome'];
$emailmobile=$row['emailmobile'];
$emailwork=$row['emailwork'];
$day=$row['day'];
$starth=$row['starth'];
$startm=$row['startm'];
echo ("<tr><td style='text-align:center'>".$stuno."</td><td>".$day." (".$starth.":".$startm.")</td><td>".$fname." ".$lname."</td><td>");
if (!empty($emailhome)) {
echo("<input class='checkbx' type='checkbox' name='email[$count]' value='".$emailhome."'>");
echo("<span style='color:#4B0082;'>Home (".$emailhome.")</span><br>");
$count++;
} else {
echo("");
}
if (!empty($emailmobile)) {
echo("<input class='checkbx' type='checkbox' name='email[$count]' value='".$emailmobile."'>");
echo("<span style='color:#006400;'>Mobile (".$emailmobile.")</span><br>");
$count++;
} else {
echo("");
}
if (!empty($emailwork)) {
echo("<input class='checkbx' type='checkbox' name='email[$count]' value='".$emailwork."'>");
echo("<span style='color:#FF4500;'>Work (".$emailwork.")</span> ");
$count++;
} else {
echo("");
}
echo("</td></tr>");
} //j
$howlist=$_POST['howlist'];
echo("<input type='hidden' name='howlist' value=".$howlist.">");
?>
<tr><td colspan="2" align="center" style='color:red;border:solid 2px red'>
<div id="test">
<input type="button" onclick='selects()' value="Select All"/>
<input type="button" onclick='deSelect()' value="Deselect All"/></td>
</div>
<td style="background-color:#898d8f; padding:8px;" colspan="2" align="center"><input type="submit" name="submit" value="COMPOSE MESSAGE" class="button" >
<input type="reset" value="Clear Form" class="button">
<input type="button" class="button" value="Return to main menu" onClick="window.location='../index.php';">
</td></tr></table>
</form>
<?php
exit();
} //p
?>
<!-- front page -->
<form name="mainform" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table align="center" style="border:0; font-size: 20px; margin-top:100px;"><tr><td style="border:0; color:#ee2222; padding:8px">
How would you like the list of students presented?</td></tr>
<tr><td style="border:0; padding:8px"><input type="checkbox" name="howlist" value="allabc"> All names in alphabetical order</td></tr>
<tr><td style="border:0; padding:8px"><input type="checkbox" name="howlist" value="allclass"> All names grouped by class</td></tr>
<tr><td style="background-color:#898d8f; padding:8px;" align="center"><input type="submit" name="submit" value="GET LIST" class="button" style='width:90px'>
<input type="reset" value="Clear Form" class="button">
<input type="button" value="Return to main menu" onClick="window.location='../index.php';" class="button" />
</td></tr>
</table>
</form>
</body>
</html>