我使用phpmailer从数据库发送电子邮件到电子邮件地址,这是有效的。 但我想通过复选框选择电子邮件地址,这不起作用。 我没有错误,但我使用var_dump,问题是代码没有看到数据库中的id。 var_dump是:1string(33)“DELETE FROM memberlist WHERE id = o” 有人能帮助我吗?
提前感谢。
我的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 = 'test@gmail.com'; // 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>
答案 0 :(得分:0)
DELETE
删除数据但不回复。所以你应该为SELECT
指令更改它
您的WHERE id = o
似乎也是错误的,请检查您的复选框值。如果您没有更多的帮助,请发布您的HTML代码(带复选框)。