douxi3233 2019-02-21 11:40
浏览 71

从phonegap android应用程序发送电子邮件

I want to send a feedback form from android PhoneGap application i have used following code which is not working

1) i have used bellow Ajax code and JQuery files to send ajax request and HTML form, i want to send the email of 4 html fields

<script type="text/javascript" src="assets/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="assets/js/jquery.js"></script>
    <script type="text/javascript" src="assets/js/geturi.js"></script>
     <script type="text/javascript">
    $(document).ready(function() {
        $("#send").click(function() {
            var fullName = $("#fullName").val();
            var emailId = $("#emailId").val();
            var mobileNo = $("#mobileNo").val();
            var message = $("#message").val();
            var dataString = "fullName=" + fullName + "&emailId=" + emailId + "&mobileNo=" + mobileNo + "&message=" + message + "&send=";
            if ($.trim(fullName).length > 0 & $.trim(emailId).length > 0 & $.trim(mobileNo).length > 0 & $.trim(message).length > 0) {
                $.ajax({
                    type: "POST",
                    url: "https://www.activebittechnologies.com/phonegap/mail.php",
                    data: dataString,
                    crossDomain: true, 
                    cache: false,
                    beforeSend: function() {
                        $("#send").val('Sending Enquiry...');
                    },
                    success: function(data) {
                        if (data == "success") {
                            alert("Mail Sent");
                            $("#send").val('submit');
                        } else if (data == "error") {
                            alert("error");
                        }
                    }
                });
            }
            return false;
        });
    });
    </script>


<div class="content form">
                        <div class="header">
                            <div class="header-overlay"></div><img src="assets/banner/5.jpg">
                            <div class="info">
                                <h3 class="title">Send Contact Enquiry</h3> 
                                <span data-close="#enquirepop" class="closeit"><i class="fa fa-times" aria-hidden="true"></i></span>
                                </div>
                        </div>

                        <div class="form-group">
                            <input id="fullName" name="fullName" type="text" class="form-control" placeholder="Full Name">
                        </div>
                        <div class="form-group">
                            <input id="emailId" name="emailId" type="text" class="form-control" placeholder="Email Id">
                        </div>
                        <div class="form-group">
                            <input id="mobileNo" name="mobileNo" type="text" class="form-control" placeholder="Mobile No">
                        </div>
                        <div class="form-group">
                            <textarea class="form-control" id="message" name="message" placeholder="Your Message" style="color:#fff;"></textarea>
                        </div>
                        <div class="text-right">
                            <input type="button" id="send" class="btn btn-primary" value="Send">
                        </div>


                    </div>

unable to go on this page from phone gap when installed on android phone bellow is php script which is on server

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS");
$toEmail = "hotelinkonkan@gmail.com";
$mailHeaders = "From: " . $_POST["fullName"] . "<". $_POST["emailId"] .">
";
$sentml=mail($toEmail, $_POST["fullName"], $_POST["message"], $mailHeaders);

if($sentml)
echo"success";
else 
echo"error";

?>
  • 写回答

1条回答 默认 最新

  • dt2015 2019-02-21 12:35
    关注

    I use $("#form1").serialize() to get all the values from the form, and I validate the values on the server side. You should always validate your values server side, because users can send a direct post to your php without any javascript validation.

    Hope it helps.

    <script type="text/javascript" src="assets/js/jquery-3.1.1.min.js"></script>
        <script type="text/javascript" src="assets/js/jquery.js"></script>
        <script type="text/javascript" src="assets/js/geturi.js"></script>
         <script type="text/javascript">
        $(document).ready(function() {
            $("#send").click(function() {
    
                    $.ajax({
                        type: "POST",
                        url: "https://www.activebittechnologies.com/phonegap/mail.php",
                        data: $("#form1").serialize(), 
                        crossDomain: true, 
                        cache: false,
                        beforeSend: function() {
                            $("#send").val('Sending Enquiry...');
                        },
                        success: function(data) {
                             console.log(data);
                            if (data == "success") {
                                alert("Mail Sent");
                                $("#send").val('submit');
                            } else if (data == "error") {
                                alert("error");
                            }
                        }
                    });
    
                return false;
            });
        });
        </script>
    
    <form id='form1' >
    <div class="content form">
                            <div class="header">
                                <div class="header-overlay"></div><img src="assets/banner/5.jpg">
                                <div class="info">
                                    <h3 class="title">Send Contact Enquiry</h3> 
                                    <span data-close="#enquirepop" class="closeit"><i class="fa fa-times" aria-hidden="true"></i></span>
                                    </div>
                            </div>
    
                            <div class="form-group">
                                <input id="fullName" name="fullName" type="text" class="form-control" placeholder="Full Name">
                            </div>
                            <div class="form-group">
                                <input id="emailId" name="emailId" type="text" class="form-control" placeholder="Email Id">
                            </div>
                            <div class="form-group">
                                <input id="mobileNo" name="mobileNo" type="text" class="form-control" placeholder="Mobile No">
                            </div>
                            <div class="form-group">
                                <textarea class="form-control" id="message" name="message" placeholder="Your Message" style="color:#fff;"></textarea>
                            </div>
                            <div class="text-right">
                                <input type="button" id="send" class="btn btn-primary" value="Send">
                            </div>
    
    
                        </div></form>
    
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?