如何将下拉菜单的选定值发送到电子邮件? [英] How to send the selected value of a drop down menu to an email?

查看:61
本文介绍了如何将下拉菜单的选定值发送到电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,它将下拉菜单的选定值发送到php中的电子邮件中.我已经将文本值发送到电子邮件了.但是我不知道如何将下拉菜单值发送到电子邮件.我做了一些代码.但这是行不通的.谁能支持我. 这是php,HTML和JS代码.

I have an question that send the selected value of a drop down menu to an email in php. I already send the text values to a email. But I did not know how to send the drop down menu value to a email. I did some code. But it does not work. Could anyone support me. Here is the php, HTML and JS code.

php代码...

<?php
if(isset($_POST['contactFrmSubmit']) && !empty($_POST['name']) && !empty($_POST['email']) && (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) && !empty($_POST['message'])){


    // Submitted form data
    $name   = $_POST['name'];
    $email  = $_POST['email'];
    $message= $_POST['message'];


    /*
     * Send email to admin
     */
    $to     = 'support@ribelz.net';
    $subject= 'Contact Request of privateeyelk.com';

    $htmlContent = '
    <h4>Contact request from : '.$email.'</h4>

    <p>Name: '.$name.'</p>
    <p>Email: '.$email.'</p>
    <p>Message: '.$message.'</p>

     ';



    // Set content-type header for sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // Additional headers
    $headers .= 'From: Private Eye<privateeyelk.com>' . "\r\n";

    // Send email
    if(mail($to,$subject,$htmlContent,$headers)){
        $status = 'ok';
    }else{
        $status = 'err';
    }

    // Output status
    echo $status;die;

    }

?>

HTML代码...

HTML code...

<!-- Contact form -->

 <div class="modal fade" id="modalForm" role="dialog" style="width: 100%;">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Contact Form</h4>
            </div>

            <!-- Modal Body -->
            <div class="modal-body">
                <p class="statusMsg"></p>
                <form role="form">
                    <div class="form-group">
                        <label for="inputName">Name</label>
                        <input type="text" class="form-control" id="inputName" placeholder="Enter your name" style="border: 1px solid #fff; border-bottom: 1px solid #ccc;"/>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">Email</label>
                        <input type="email" class="form-control" id="inputEmail" placeholder="Enter your email"/>
                    </div>
                    <div class="form-group">
                        <label for="inputMessage">Message</label>
                        <textarea class="form-control" id="inputMessage" placeholder="Enter your message"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="inputMessage">Services</label>
                        <select name="size" class="form-control"
                        id="inputService" size="1">
                        <option value="Option1">Pr-Matrimonial Services</option>
                        <option value="Option2">Extra Marital Affairs</option>
                        <option value="Option3">Divorce Case Support</option>
                        </select>
                    </div>
                </form>
            </div>

            <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary submitBtn" onclick="submitContactForm()">SUBMIT</button>
            </div>
        </div>
    </div>
</div>

JS代码...

<script>
function submitContactForm(){
    var usernameRegex = /^[a-zA-Z0-9]+$/;
    var reg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
    var name = $('#inputName').val();
    var email = $('#inputEmail').val();
    var message = $('#inputMessage').val();
    var service = $('#inputService').val();
    if(name.trim() == '' ){
        alert('Please enter your name.');
        $('#inputName').focus();
        return false;
    }else if(name.trim() != '' && !usernameRegex.test(name)){
        alert('Please enter valid name.');
        $('#inputName').focus();
        return false;
    }else if(email.trim() == '' ){
        alert('Please enter your email.');
        $('#inputEmail').focus();
        return false;
    }else if(email.trim() != '' && !reg.test(email)){
        alert('Please enter valid email.');
        $('#inputEmail').focus();
        return false;
    }else if(message.trim() == '' ){
        alert('Please enter your message.');
        $('#inputMessage').focus();
        return false;
    }else if(service.trim() == '' ){
        alert('Please select your service.');
        $('#inputService').focus();
        return false;
    }else{
        $.ajax({
            type:'POST',
            url:'contact.php',
            data:'contactFrmSubmit=1&name='+name+'&email='+email+'&message='+message+'&service='+service,
            beforeSend: function () {
                $('.submitBtn').attr("disabled","disabled");
                $('.modal-body').css('opacity', '.5');
            },
            success:function(msg){
                if(msg == 'ok'){
                    $('#inputName').val('');
                    $('#inputEmail').val('');
                    $('#inputMessage').val('');
                    $('#inputService').val('');
                    $('.statusMsg').html('<span style="color:green;">Thanks for contacting us, we\'ll get back to you soon.</p>');
                }else{
                    $('.statusMsg').html('<span style="color:red;">Some problem occurred, please try again.</span>');
                }
                $('.submitBtn').removeAttr("disabled");
                $('.modal-body').css('opacity', '');
            }
        });
    }
}
</script>

推荐答案

只需添加一个新变量:

$value_from_dropdown = $_POST['your_select_name'];

然后,您可以像其他任何变量一样在脚本中使用该变量

Then you can use that variable in your script like you do for any other variable

这篇关于如何将下拉菜单的选定值发送到电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆