【问题标题】:sending phpmailer on data deletion在数据删除时发送 phpmailer
【发布时间】:2017-02-01 06:00:02
【问题描述】:

我有一个表单,可以将用户添加到 mysql 数据库表并将新信息通过电子邮件发送到地址(工作)。

现在我有一个用于从表中删除记录的表单,但我无法让它在删除之前通过电子邮件发送旧用户数据。

例如,如果用户从表中删除 id 45,则必须发送一封电子邮件,说明“用户已从表中删除:‘姓名’、‘电话’、‘分机’”

delete.php 的代码:

<?php
require ("database.php");  

?> 

<?php


$this_Stud_ID =$_REQUEST['id'];

    // sending query
    mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")
    or die(mysql_error());          


    if($_POST['action'])

header("Location: index.php");
?>
<form action="<?php echo $_SERVER['php_self'] ?>" method="post">
Enter ID Number :<br><input type="text" name="id"><br />
<br><input type="submit" name="action" value="Delete!">
<br> <br>
<h3>
<a href="index.php"> Main Menu </a> 
</h3>
</form>

【问题讨论】:

    标签: php html mysql phpmailer


    【解决方案1】:

    您必须在删除之前获取用户数据。 做这样的事情

    <?php
    require ("database.php");
    if(isset($_POST['action'])){
        if(isset($_REQUEST['id']) && (int)$_REQUEST['id']>0){
            $this_Stud_ID =(int)$_REQUEST['id'];
            $user_record=mysql_fetch_assoc(mysql_query('select * from users where id=' . $this_Stud_ID));
            //now send an email to user or to anyone and use $user_record as user data
            $to='';
            $subject='';
            $message='';
            $headers='';
            $mail_status=mail($to, $subject, $message, $headers);
            if($mail_status){
                mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")or die(mysql_error());          
                header("Location: index.php");
                exit();
            }
        }
    }
    ?>
    <form action="<?php echo $_SERVER['php_self'] ?>" method="post">
        Enter ID Number :<br><input type="text" name="id"><br />
        <br><input type="submit" name="action" value="Delete!">
        <br> <br>
        <h3><a href="index.php"> Main Menu </a></h3>
    </form>
    

    【讨论】:

    • 使用phpmailer还是可以的?
    【解决方案2】:

    看起来代码不完整! 在表单提交时,首先使用WHERE id = $this_Stud_ID 获取数据 并执行
    mail("yourname@domain.com","Subject","phone no name ..etc");
    然后就可以执行了

    mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")
    or die(mysql_error()); 
    

    请发布您的完整代码!

    【讨论】:

    • 所以。您不是在 delete.php 中编写邮件的代码吗?检查@GauravRai 的答案。
    • 正确我会尝试 Gaurav 上面给出的答案,看看是否可行
    • 我顺便用了phpmailer
    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 2017-04-09
    • 2011-10-01
    • 2021-12-06
    • 2021-12-03
    • 2015-12-18
    • 2015-05-21
    • 1970-01-01
    相关资源
    最近更新 更多