简体   繁体   English

我想通过电子邮件发送此表格的详细信息,

[英]I want to send the details of this form as an email,

The mailing address depends on the city selected from the dropdown list.I have troubles with the php code.please help me. 邮寄地址取决于从下拉列表中选择的城市。我对php代码有疑问。请帮助我。

<form action="">
        <ul>
            <li><input name="name" type="text" placeholder="type name" /></li>
            <li><input name="email" type="email"  placeholder="type email"/></li>
            <li><input name="num" type="number" placeholder="type contact number" /></li>
           <div class="dropdown">
<button type="button" class="btn btn-lg dropdown-toggle btn-block" data-toggle="dropdown" id="city">
     Select City
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
      <li><a href="javascript:void(0);">Sydney</a></li>
      <li><a href="javascript:void(0);">Brisbane</a></li>
      <li><a href="javascript:void(0);">Melbourne</a></li>
      <li><a href="javascript:void(0);">Canberra</a></li>
      <li><a href="javascript:void(0);">Darwin</a></li>
      <li><a href="javascript:void(0);">Perth</a></li>

    </ul>
</div>
            <li><input name="submit" type="submit" /></li>
        </ul>

    </form>

there is my php try 有我的PHP尝试

if(isset($_POST['submit'])) {
 switch($_POST['city']) {
  case 'Sydney': $to = 'to1@gmail.com'; break;
  case 'Brisbane': $to = 'to2@hotmail.com'; break;
 }
}

please see below. 请参阅下面。 I have tried and tested code below and it works. 我已经尝试并测试了下面的代码,它可以工作。 try it out. 试试看。

<html>
    <head>
            <title>Sending Email</title>
            <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
            <script type="text/javascript">
                    $(document).ready(function () {

                    $("#Send").click(function(){
                        var Name=$('#Name').val();
                        var Email=$('#Email').val();
                        var Num=$('#Num').val();
                        var City= $("#City option:selected").text();

                        $.post('sendmail.php',{Name:Name,Email:Email,Num:Num, City:City},function(data){

                    alert(data);

                    });



                    });


                    });                 
            </script>
    </head>

    <body>
            <form onsubmit="return false;" id="UserReg">

             <ul>
                        <li>Name:<input id="Name"  type="text" placeholder="type name" /></li>
                        <li>Email:<input id="Email" type="email"  placeholder="type email"/></li>
                        <li>Number:<input id="Num" type="text" placeholder="type contact number" /></li>
                        <li>City:<select id="City">
                        <option value=""></option>
                        <option value="Sydney">Sydney</option>
                        <option value="Brisbane">Brisbane</option>
                        <option value="Melbourne">Melbourne</option>
                        <option value="Canberra">Canberra</option>
                        <option value="Darwin">Darwin</option>
                        <option value="Perth">Perth</option>

                        </select>


            </ul>           



            <input type="submit" value="Send" id="Send"/>

            </form>
    </body>
<html>

<?php
    if($_POST)
    {
        $Name=$_POST["Name"];
        $Email=$_POST["Email"];
        $Num=$_POST["Num"];
        $City=$_POST["City"];
        $To;

    switch($City) {
      case 'Sydney': $To = 'to1@gmail.com'; break;
      case 'Brisbane': $To = 'to2@hotmail.com'; break;
                        }

        $Message="Name is".$Name." Email is:".$Email." Num is:".$Num;

    $Send=mail($To,"Details of".$Name,$Message) 
    if($Send)
    {
        echo "Email Sent to".$City;
        exit();
    }
    else
    {

    echo "Error encountered";
    exit();

    }


    }
?>

because you are not submitting any input regarding city. 因为您没有提交有关城市的任何输入。 use an html input element for city to get it submitted to be available with $_POST here are the list of input elements: http://www.w3schools.com/html/html_forms.asp 使用城市的html输入元素将其提交以供$ _POST使用,以下是输入元素的列表: http : //www.w3schools.com/html/html_forms.asp

on submitting page will redirect to secondpage.php and from the second page mail will go as follows 在提交页面上将重定向到secondpage.php,从第二页发送的邮件将如下所示

and //secondpage.php 和//secondsecond.php

$body=$_POST['name']; $ body = $ _ POST ['name']; mail ($to, $subject, $body, $headers) 邮件($ to,$ subject,$ body,$ headers)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将表单详细信息发送到电子邮件 - Send form details to email 如何将表单详细信息发送到数据库以及如何发送包含表单详细信息的电子邮件CodeIgniter - How to send form details to database and send email with form details CodeIgniter 我正在尝试使用PHP从FORM发送电子邮件,但是我收到的详细信息没有发件人电子邮件地址 - I am trying to send email from a FORM using PHP, but i receive the details without the From email Address onClick获取表单详细信息并发送电子邮件 - onClick get form details and send email 我想从发送电子邮件时显示弹出窗口的 html 表单发送电子邮件 - I want to send an email from an html form that shows a popup when the email is sent 为什么我的 html/css/php 表单只会在电子邮件地址有效时向我发送电子邮件? 我想要一个电子邮件无论如何 - Why will my html/css/php form only send me an email when the email address is valid? I want an email regardless 我的php不会将联系表的详细信息发送到我的电子邮件 - My php will not send the details of the contact form to my email 是否可以使用wamp在php中发送电子邮件以及表单详细信息 - Is it possible to send email along with form details in php using wamp 如何在忍者形式的电子邮件中发送 woocommerce 购物车详细信息? - How to send a woocommerce cart details in ninja form email? 我想使用改进的 Laravel 电子邮件发送电子邮件,我想随视图一起发送一些变量 - I want to send email using improved laravel email, I want to send some variable along with view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM