根据下拉菜单选择发送电子邮件(mysql列更新/状态更改)

时间:2018-09-08 05:12:37

标签: php mysql

每当将其他选择发布到数据库时,我都希望发送电子邮件。

<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post" enctype="multipart/form-data">
                    <div class="form-group row <?php echo (!empty($lotstatus_err)) ? 'has-error' : ''; ?>">
                        <div class="col-lg-4">
                                <label class="form-control-label">Status</label>
                                <select class="form-control" value="<?php echo $lotstatus; ?>" id="lotstatus" name="lotstatus">
                                <option value="Executed">Executed</option>
                                        <option value="Not Interested" <?php if($row["lotstatus"]=='Not Interested'){ echo "selected";} ?>>Not Interested</option>
                                        <option value="Hold" <?php if($row["lotstatus"]=='Hold'){ echo "selected";} ?>>Hold</option>
                                        <option value="Title Ordered" <?php if($row["lotstatus"]=='Title Ordered'){ echo "selected";} ?>>Title Ordered</option>
                                        <option value="Vetting" <?php if($row["lotstatus"]=='Vetting'){ echo "selected";} ?>>Vetting</option>
                                        <option value="Survey Ordered" <?php if($row["lotstatus"]=='Survey Ordered'){ echo "selected";} ?>>Survey Ordered</option>
                                        <option value="Lean Search Ordered" <?php if($row["lotstatus"]=='Lean Search Ordered'){ echo "selected";} ?>>Lean Search Ordered</option>
                                        <option value="Clear to Closed" <?php if($row["lotstatus"]=='Clear to Closed'){ echo "selected";} ?>>Clear to Closed</option>
                                        <option value="Closed" <?php if($row["lotstatus"]=='Closed'){ echo "selected";} ?>>Closed</option>
                                </select>

因此,当用户更新状态时,会发送一封电子邮件,指出“此记录已从“以前的状态”更新为“新的状态”。我在准备好的声明中有此记录:

if(isset($_POST["lotstatus"]) && !empty($_POST["lotstatus"])){ 
    $lotstatusPost = $_POST['lotstatus']; 
    $lotstatus = $row['lotstatus'];
    $streetnumber = $row['streetnumber'];
    $streetname = $row['streetname'];

    if($lotstatus != $lotstatusPost) {
        $email='al@gmail.com';
        $subject = "Lot Status Change";
        $message =$streetnumber. ' '. $streetname. ' '. 'Lot Status has changed from'.' '. $lotstatus. ' '. 'to'.' '. $lotstatusPost;
        $headers = "From: My Company"; 
        
        mail($email, $subject, $message, $headers); 
            //mail successfully sent
        
    }
}

没有错误。它只是不发送。或者,如果我不检查它是否已设置,则当我进入更新页面而没有_POST字段时,它将发送。 帮助!

1 个答案:

答案 0 :(得分:0)

将原始值存储到表单上的隐藏字段中,即

<input type-'hidden' name='oldLostStatus' value="<?php echo $row["lotstatus"];?>">

然后在处理时-选择旧值,即

$lotstatus = $_POST['oldLotStatus'];

也是您的代码:

$streetnumber = $row['streetnumber'];
$streetname = $row['streetname'];

无法正常工作,因为您没有从表单中获取值-使用

$streetnumber = $_POST['streetnumber'];
$streetname = $_POST['streetname'];