将HTML表转换为PHP电子邮件表

时间:2014-04-22 21:01:04

标签: php html html-email

我想知道我将如何使用HTML填充表(基于用户输入和输入字段)并使用PHP将其变成一个表,其中包含用户在表中的输入值。

HTML

<div class="table-responsive">
              <table class="table">
                <thead>
                  <tr>
                    <th>&nbsp;</th>
                    <th>Team</th>
                    <th>1</th>
                    <th>2</th>
                    <th>3</th>
                    <th>4</th>
                    <th>5</th>
                    <th>6</th>
                    <th>7</th>
                    <th>8</th>
                    <th>9</th>
                    <th>10</th>
                    <th>11</th>
                    <th>12</th>
                    <th>R</th>
                    <th>H</th>
                    <th>E</th>
                    <th>Record</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="bold">V</td>
                    <td><input class="form-control team-wide" type="text"  name="visitorTeamname" id="visitorTeamName"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 1" id="visitorinning1"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 2" id="visitorinning2"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 3" id="visitorinning3"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 4" id="visitorinning4"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 5" id="visitorinning5"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 6" id="visitorinning6"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 7" id="visitorinning7"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 8" id="visitorinning8"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 9" id="visitorinning9"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 10" id="visitorinning10"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 11" id="visitorinning11"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Visitor Inning 12" id="visitorinning12"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="visitor R" id="visitorR"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="visitor H" id="visitorH"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="visitor E" id="visitorE"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="visitor Record" id="visitorRecord"></td>

                  </tr>
                  <tr>
                    <td class="bold">H</td>
                    <td><input class="form-control team-wide" type="text"  name="HomeTeamName" id="HomeTeamName"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 1" id="homeinning1"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 2" id="homeinning2"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 3" id="homeinning3"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 4" id="homeinning4"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 5" id="homeinning5"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 6" id="homeinning6"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 7" id="homeinning7"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 8" id="homeinning8"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 9" id="homeinning9"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 10" id="homeinning10"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 11" id="homeinning11"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Inning 12" id="homeinning12"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home R" id="homeR"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home H" id="homeH"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home E" id="homeE"></td>
                    <td><input class="form-control inning-wide reverse-20" type="text"  name="Home Record" id="homeRecord"></td>
                  </tr>
                </tbody>
              </table>
        </div><!-- /.table-responsive -->

PHP

 // get the posted data

$name = $_POST["name"];
$email = $_POST["email"];
$dateMonth = $_POST["dateMonth"];
$dateDay = $_POST["dateDay"];
$bbsb = $_POST["bbsb"];
$gameType = $_POST["type"];
$comments = $_POST["comments"];
$ThanksURL = "thanks.php"; //confirmation page
// write the email content
$email_content .= "Name: $name\n";
$email_content .= "Email: $email\n";
$email_content .= "Date: $dateMonth $dateDay\n";
$email_content .= "Game: $bbsb - $gameType\n";

//Where I would like the table to start
$email_content .= "Comments:\n\n$comments";

// send the email

任何帮助都表示赞赏,或者如果有人可以帮助我们开始,我可以完成它。

谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个 -

// write the email content
$email_content = "<table>";
$email_content .= "<tr>
                 <th>Name</th>
                 <td>$name</td>
                  </tr>";
$email_content .= "<tr>
                 <th>Email</th>
                 <td>$email</td>
                  </tr>";
$email_content .= "<tr>
                 <th>Date</th>
                 <td>$dateMonth $dateDay</td>
                  </tr>";
$email_content .= "<tr>
                 <th>Game</th>
                 <td>$bbsb - $gameType</td>
                  </tr>";
$email_content .= "<tr>
                 <th>Comments</th>
                 <td>$comments</td>
                  </tr>";
$email_content .= "</table>";