从下拉列表和文件上传调用php函数

时间:2015-08-25 23:02:55

标签: php select

我的网站有以下代码,用于在用户点击上传文件按钮时上传文件,并向静态电子邮件地址发送电子邮件。但是,我试图让用户能够从下拉列表中选择收件人。我已经找到了几种方法来分别完成这两个方面,但我不知道如何在我调用$ mailer函数时将$ recip设置为Person1或Person2 @ xyz.com,同时发布文件上传。
我感谢任何帮助。

<?php if( !empty($upload_output) ): ?>    
<?php
// if not empty send one email
$subuser = $session->username;
$mailer->sendUploadNotice($subuser,$config,$recipient);
endif; ?>   


<form method="post" action="" enctype="multipart/form-data">
<p><b>Step 1</b> Choose file to upload: <input name="upload_file[]" id="upload_file[]" type="file" class="inputtext" /></p> 
<p><b>Step 2</b> Choose a recipient 
<select>
<option value="person1@xyz.com" selected>person1@example.com</option>
<option value="person2@xyz.com">person2@example.com</option>
</select> </p>
<p><b>Step 3</b> Click the Upload File button </p><input type="submit" name="submit" value="Upload File" />
</form>

2 个答案:

答案 0 :(得分:0)

<?php if( !empty($upload_output) ): ?>    
<?php
// if not empty send one email
$recipient = $_POST['recipient'];
$subuser = $session->username;
$mailer->sendUploadNotice($subuser,$config,$recipient);
endif; ?>   


<form method="post" action="" enctype="multipart/form-data">

    <p><b>Step 1</b> Choose file to upload: <input name="upload_file[]" id="upload_file[]" type="file" class="inputtext" /></p> 
    <p><b>Step 2</b> Choose a recipient 
    <select name="recipient">
    <option value="person1@xyz.com" selected>person1@example.com</option>
    <option value="person2@xyz.com">person2@example.com</option>
    </select> </p>
    <p><b>Step 3</b> Click the Upload File button </p><input type="submit" name="submit" value="Upload File" />
    </form>

select框中添加名称,然后使用$_POST获取所选选项的值

答案 1 :(得分:0)

如果您想从数据库中填充HTML Drop,请尝试使用

<?php
$query = "SELECT * FROM `your table` ORDER BY `name` ASC";
$result = $mysqli->query( $query );

while( $row = $result->fetch_assoc() ){

        extract($row);
        //echo the row into option value, email in the value and display name in the display area
{
    $aa .= "<option value='{$row['email']}'>{$row['name']}</option>";

}
?>

这就是我填充HTML下拉列表的方式。

<select name="recipient" required>
        <option value="">Select Name</option>
        <?php echo$aa; ?></select>

将此添加到您的其余代码中,您应该好好去