本文介绍了如何获取一组下拉列表值并使用PHP发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个下拉列表 - 一组。

I have three dropdown list - a set.

可以在这里检查演示页面:

Demo page can be inspected here : http://goo.gl/VqtTyM


  1. 第一个是目的地

  2. 第二个是选择客户兴趣在'目的地'中的吸引力或
    活动

  3. 第三是可用的吸引力/活动'在'目的地'

由以下代码创建:

<div class="multi-field">
    <select class="text-one" name="destination[]">
        <option selected value="base">Please Select</option>
        <option value="colombo">Colombo</option>
        <option value="kandy">Kandy</option>
        <option value="anuradhapura">Anuradhapura</option>
    </select>
    <br />

    <select class="text-two" name="attraction_or_activity[]">
        <option value="attraction_or_activity">Select the attractions or activities</option>
        <option value="attraction">Attraction</option>
        <option value="activity">Activity</option>
    </select>

    <select class="populated_attr_or_activity" name="attraction_or_activity_selected[]">
        <option value="available_attr_act">Available attractions / activities</option>
        <!-- Here, available options will be populated -->
    </select>
</div>

客人根据需要选择了该选项,并提交表单,我应该收到这些选择到我的电子邮件

After guest selected the option as they want and submit the form I should receive these selections to my email message as follow order.

目的地(第一个下拉列表中的选定值):吸引力/活动(所选值在第二个下拉列表中):所选可用的吸引力/活动(第3个下拉列表中的选定值)

destination (selected value in 1st drop down list) : Attraction/Activity (selected value in 2nd drop down list) : Selected available attraction/activity (selected value in 3rd drop down list)

此下拉列表可以是通过点击添加更多添加目标)按钮更加动态地添加。
所以现在我正在使用以下代码来获取我的电子邮件。

This set of dropdown list can be added more dynamically by clicking an Add More (Add Destination) button.So for now I am using following code to get my email.

<?php
if(empty($errors)){ // if the errors array is empty then send the mail 
    $headers  = 'MIME-Version: 1.0' . "\r\n"; // adding support for HTML type email
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // adding support for HTML type email
    //print $tourist_name;
    $msg = '';
    $i = 1;
    foreach ($_POST['destination'] as $key => $val) {
        $msg .= ' <strong>' . $i++ . '. Destination : </strong>' . $val . ', <strong>Attraction/Activty : </strong>' . $_POST['attraction_or_activity'][$key] . '<br />';
    };
    $msg .= 'Name : ' .$tourist_name.'<br/>';
    $msg .= 'E-mail : ' . $tourist_email.'<br/>';
    $msg .= 'Country : ' .$tourist_country.'<br/>';
    mail("[email protected]","Custom Tour Package",$msg, $headers);
}
?>

如上所述,我只使用'destination'和'attraction_or_activity'数组。
现在我的电子邮件正文如下:

As you see above I am using 'destination' and 'attraction_or_activity' array only.now my email body looks like:

1。目的地: colombo,吸引力/活动:吸引力

1. Destination : colombo, Attraction/Activity : attraction

2。目的地: colombo,吸引力/活动:活动

2. Destination : colombo, Attraction/Activity : activity

3。目的地: kandy,吸引力/活动:吸引力

3. Destination : kandy, Attraction/Activity : attraction

姓名:来宾姓名

电子邮件:[email protected]

E-mail : [email protected]

国家:客人国家

但是我期待收到的电子邮件如下:

But how I am expecting to get the email is like below:

1。目的地: colombo,吸引力/活动:吸引力选择的吸引力/活动: Ganga Ramaya

1. Destination : colombo, Attraction/Activity : attraction Selected attraction/activity : Ganga Ramaya

2。目的地: colombo,吸引力/活动:活动选择的吸引力/活动:城市观光

2. Destination : colombo, Attraction/Activity : activity Selected attraction/activity : city tour

3。目的地: kandy,吸引力/活动:吸引力所选择的吸引力/活动: Temple Tooth

3. Destination : kandy, Attraction/Activity : attraction Selected attraction/activity : Temple Tooth

名称:访客姓名

电子邮件:[email protected]

E-mail : [email protected]

国家:客人国家

我如何修改我的代码以获得我期望的电子邮件?

how I have to modify my code to get the email as I expect above?

如何将第三个下拉列表值包含到 foreach 循环中?

how can I include 3rd dropdown lists value into foreach loop?

推荐答案

您只需要像 attraction_or_activity 一样获取 attraction_or_activity_selected 的值。尝试将 foreach 中的代码更改为:

You just need to take values of attraction_or_activity_selected like you did for attraction_or_activity. Try changing the code inside foreach to this :

foreach ($_POST['destination'] as $key => $val) {
        $msg .= ' <strong>' . $i++ . '. Destination : </strong>' . $val
                . ', <strong>Attraction/Activty : </strong>' . $_POST['attraction_or_activity'][$key]
                . ', <strong>Selected attraction/activity  : </strong>' . $_POST['attraction_or_activity_selected'][$key]
                . '<br />';

}

这篇关于如何获取一组下拉列表值并使用PHP发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 02:43