0
我使用phpmailer從數據庫發送電子郵件到電子郵件地址,該工作。 但我想通過複選框選擇電子郵件地址,這不起作用。 我沒有得到erros,但我使用var_dump,問題是代碼沒有看到數據庫中的id。 var_dump是:1string(33)「DELETE FROM memberlist WHERE id = o」 有人可以幫我嗎?PHPmailer通過複選框選擇電子郵件從數據庫發送電子郵件
在此先感謝。
我PHPMailer的代碼是:list.php的
<?php
session_start();
include 'connect.php';
echo ini_get('display_errors');
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
echo ini_get('display_errors');
//phpmailer
if(isset($_POST['submit']))
{
require "phpmailer/class.phpmailer.php"; //include phpmailer class
//this is the content of the e-mail
$message='
text: '.$_POST['textfield'].'<br />
';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'mailing';
//this is the code that select the emailaddress
$checkbox = $_POST['checkbox'];
$query = "SELECT id, name, e_mail FROM memberlist";
for($i=0;$i<count($checkbox);$i++)
{
$delete = "DELETE FROM memberlist WHERE id=$checkbox[$i]";
$result = mysqli_query($link, $query) or die(mysqli_error());
}
var_dump($delete);
$result = mysqli_query($link, $query) or die(mysqli_error());
//this is the code that send e-mail to all address in the db, this works
while ($record = mysqli_fetch_assoc($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
//$mail->MsgHTML($message);
$mail->Body = $message;
$mail->AddAddress($record["e_mail"], $record["name"]);
}
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
mysqli_close($link);
?>
我的HTML代碼是:
<form name="form1" id="form1" action="list.php" method="post">
<?php
$query = "SELECT * FROM memberlist";
$result = mysqli_query($link, $query) or die(mysqli_error());
echo "<table border='1' class='transactions'>";
echo "<tr>";
echo "<th>total</th>";
echo "<th>name</th>";
echo "<th>lastname</th>";
echo "<th>address</th>";
echo "<th>street</th>";
echo "<th>place</th>";
echo "<th>E-mail</th>";
echo "<th>Telephone</th>";
echo "<th>company</th>";
echo "<th>Select</th>";
echo "</tr>";
while ($record = mysqli_fetch_assoc($result)) {
$name = $record['name'];
$lastname = $record['lastname'];
$address = $record['address'];
$street = $record['street'];
$place = $record['place'];
$e_mail = $record['e_mail'];
$telephone = $record['telephone'];
$company = $record['company'];
echo "<tr>";
echo "<td>$name </td> <td>$lastname</td> <td>$address</td> <td>$street</td> <td>$place</td> <td>$e_mail</td> <td>$telephone</td> <td>$company</td><td><input type='checkbox' name='checkbox' id='checkItem'> Item</td>";
echo "</tr>";
}
echo "<tr><input type='checkbox' id='checkAll' name='checkbox'> check all</tr>";
echo "</table>";
?>
<br />
<textarea name="textfield" rows="4" cols="50"></textarea>
<br />
<input type="submit" name="submit" value="send" />
<p><?php if(!empty($message)) echo $message; ?></p>
<?php
mysqli_close($link);
?>
</form>
DId您將您的複選框的名稱設置爲複選框[],並將接收到的數組的計數,然後循環,而不是根據數據庫中的值進行修剪! –
把你的html代碼。 – rahul