0

I have three php pages. First is a selection.php page with options selected by checkboxes. On submit, the options are displayed and an email field (optional) to send the results to. The problem is in the email message's format. See below for code, email results, and ideal output. I appreciate anyone's help and time!

selection.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>";

    }


    ?>

results.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>";
    }

    }

    ?>

and 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:[email protected] \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...";
    }?>

Finally, this is what the actual email with results looks like-

    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>

Ideal email format could be as simple as a list (or something similar)

Stage 1- band1 2:30
Stage 1- band5 3:30
Stage 2- band4 3:10
etc...

1 Answer 1

1

Add following headers while sending mail:

$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

Sign up to request clarification or add additional context in comments.

19 Comments

I added that (see code above) yet all of the /html/ is being displayed still.
It looks good- yet I'm getting this at the end of the email message: email: [email protected] x: 0 y: 0
It's up there under EmailProcess.php
One thing I noticed- idk if it's any clue- but some examples don't use the dot before the = in the $headers= I'm using them in all as you suggested and they work now. I'm going to try added .= to the other message $
try var_dump $_POST on EmailProcesss.php and let me know what u getting
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.