PHPmailer 从数据库发送电子邮件,并通过复选框选择电子邮件

标签 php mysql

我使用 phpmailer 从数据库发送电子邮件到电子邮件地址,这有效。 但我想通过复选框选择电子邮件地址,这不起作用。 我没有收到错误,但我使用 var_dump ,问题是代码看不到数据库中的 id。 var_dump 为:1string(33)“从成员列表中删除 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>

最佳答案

SQL 中的

DELETE 删除数据并且不将其返回。因此,您应该将其更改为 SELECT 指令

您的 WHERE id = o 似乎也错误,请检查您的复选框值。如果您需要更多帮助,请发布您的 html 代码(带有复选框)。

关于PHPmailer 从数据库发送电子邮件,并通过复选框选择电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35697489/

相关文章:

php - 调用重写的父方法

PHP curl_multi - 如何限制文件的下载大小

mysql - 如何在 MySQL 或 SQL Server 中对多个表进行高效 JOIN?

mysql - 用于解密由 PBEWithMD5AndTripleDES 加密的值的 SQL 查询

php - MySQL Workbench Standard TCP/IP over SSH 的幕后命令是什么?

php - 打印指定行 mysql & PHP

javascript - 如何在动态创建的按钮的单击事件上执行 javascript 函数。

php - 使用 SOQL 选择 Salesforce 对象的所有字段

php - PHP中如何使用文件输入/输出来添加、删除和显示用户上传的数据?

php - 用户登录和注销