所选选项值未显示在电子邮件中

时间:2018-10-09 03:27:35

标签: php codeigniter web

我能够成功发送电子邮件,但所选值未显示在电子邮件中。 $ select是应该显示的那个。请帮助我。

代码如下:

    if (isset($_POST['submit']) && isset($_POST['sendMail'] ) )
        {
            $select = $_POST['datanew[co_cd]'];

            $email = "example@gmail.com";
                    $message = '<tr> <td><h2><strong>Dear </strong>'.  $select.' 
                    <h3>We would like to update you about your transaction with below details. <br>
                                BL #'.$datanew[bl_no]."
                                Container #:  6PK<br>

                                Recent Updates as of " . date('F d,Y   h:i A') . " </h3></td><tr> " ;

                    $headers  = 'mime_content_type(filename)E-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    $headers .= "From: example@gmail.com" . "\r\n";
                    mail($email,"Worksheet",$message, $headers);
            }


        else{

        }

查看页面中的代码:

<select class="form-control" name="datanew[co_cd]">
<option value="">Choose Client</option>
 <?php foreach($client as $clientrow) : 
                                if 
($transdbrow['co_cd']===$clientrow['co_cd']) {
echo '<option value="' . $clientrow['co_cd'] . '" selected>' . 
$clientrow['co_name'] . '</option>';
} 
else {
echo '<option value="' . $clientrow['co_cd'] . '">' . $clientrow['co_name'] 
. '</option>';
}
endforeach;

$client = $client;?>                            
</select>

1 个答案:

答案 0 :(得分:1)

PHP将您的选择名称解释为名为datanew的数组,因此访问该值的正确方法是

$select = $_POST['datanew']['co_cd'];