繁体   English   中英

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

[英]PHPmailer sending e-mail from database with select e-mail by checkbox

我使用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代码(带复选框)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM