1
有人可以幫我修復我的代碼嗎?通過PHP使用HTML表格發送MySQL表格
我想根據HTML表單檢索我的數據庫中的一些數據並通過電子郵件(PHP)發送。
HTML表單:(此表工作正常,我在這裏看不到任何問題)
<form method="post" action="valid_tasks.php">
<div class="form-group">
<label for="mailTo">To:</label>
<select class="form-control" id="mailTo" name="mailTo">
<?php echo showUsers(); ?>
</select>
</div>
<div class="form-group">
<label for="statusTo">Task Status:</label>
<select class="form-control" id="statusTo" name="statusTo">
<?php echo showStatus(); ?>
</select>
</div>
<input type="submit" name="submitMail" id="submitMail" class="btn btn-info" value="Send" style="margin-bottom: 20px;">
</form>
PHP:(我使用此代碼作爲另一頁上的功能,它似乎工作也沒關係,這是一個有點不同,但它的工作原理)
<?php
require_once('db.class.php');
$objDb = new db();
$link = $objDb->conecta_mysql();
if(isset($_POST['submitMail']))
{
$status = $_POST['statusTo'];
$userMail = $_POST['mailTo'];
$id = $_SESSION['id'];
$username = $_SESSION['username'];
$query = "SELECT T.setor, T.taskWhat, T.taskWho, DATE_FORMAT(T.deadLine,'%d/%m/%Y') AS deadLine,";
$query .= "T.taskStatus, U.username, U.email, S.descricao, S.abDescri";
$query .= "FROM tarefas AS T LEFT JOIN status AS S ON T.taskStatus = S.abDescri ";
$query .= "LEFT JOIN users AS U ON U.username = T.taskWho ";
$query .= "WHERE T.taskWho = '$userMail' AND S.abDescri = '$status'";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($result)){
$setor = $row['setor'];
$taskWhat = $row['taskWhat'];
$taskWho = $row['taskWho'];
$deadLine = $row['deadLine'];
$taskStatus = $row['taskStatus'];
$userAcao = $row['username'];
$emailAcao = $row['email'];
$statusDescri = $row['descricao'];
$statusAb = $row['statusAb'];
$setor = mysqli_escape_string($link, $setor);
$taskWhat = mysqli_escape_string($link, $taskWhat);
$taskWho = mysqli_escape_string($link, $taskWho);
$deadLine = mysqli_escape_string($link, $deadLine);
$taskStatus = mysqli_escape_string($link, $taskStatus);
$userAcao = mysqli_escape_string($link, $userAcao);
$emailAcao = mysqli_escape_string($link, $emailAcao);
$statusDescri = mysqli_escape_string($link, $statusDescri);
$statusAb = mysqli_escape_string($link, $statusAb);
echo
'<tr>
<td>'.$setor.'</td>
<td>'.$taskWhat.'</td>
<td>'.$deadLine.'</td>
<td>'.$taskWho.'</td>
<td>'.$statusAb.'</td>
</tr>';
}
}
電子郵件:(我已經看到了很多關於如何使用它的例子,但他們都不是有關從HTML表單獲取信息並將其放入PHP郵件中)
$to = $email;
$subject = "Tarefas com status ".$status;
$message = "
<html>
<head>
<title>HTML email</title>
<link rel='stylesheet' type='text/css' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
</head>
<body>
<div class='container'>
<center><h1>Hello, ".$username."!</h1></center>
</div>
// I NEED TO PUT THIS INFO HERE
</div>
</body>
</html>
謝謝大家!
您可以發佈你遇到的一些錯誤? – ldrg
看看phpMailer。你將需要包括圖書館。這裏是一個例子,從一個HTML聯繫表格 https://github.com/PHPMailer/PHPMailer/blob/master/examples/contactform.phps –
我不知道如何顯示該信息到電子郵件腳本。我認爲,我的HTML和PHP工作正常。 –