Javascript 在PHP和jQuery Mobile中使用SendGrid

Javascript 在PHP和jQuery Mobile中使用SendGrid,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,好吧,我被困在这里了。我一直在尝试建立一个web表单,以便通过电子邮件通知注册我的移动应用程序的用户。我希望覆盖ajax的默认行为,因为最终(与现在不一样)我希望在前几页不处理提交 我的目标是让用户提交jQuery Mobile表单,让ajax将表单数据发送到我的php脚本,该脚本将使用SendGridapi将用户数据通过电子邮件发送给我。但现在它对我不起作用 该页面位于运行Linux的google compute engine实例上,PHP已正确安装,当单击发送按钮但没有电子邮件时,表单会显示

好吧,我被困在这里了。我一直在尝试建立一个web表单,以便通过电子邮件通知注册我的移动应用程序的用户。我希望覆盖ajax的默认行为,因为最终(与现在不一样)我希望在前几页不处理提交

我的目标是让用户提交jQuery Mobile表单,让ajax将表单数据发送到我的php脚本,该脚本将使用SendGridapi将用户数据通过电子邮件发送给我。但现在它对我不起作用

该页面位于运行Linux的google compute engine实例上,PHP已正确安装,当单击发送按钮但没有电子邮件时,表单会显示甚至刷新(

顺便说一句,当使用后缀从命令行启动时,SendGrid在我的服务器上运行良好

本教程的链接如下:

请帮忙

mailer.php后接postScript.js后接webformcomplete.php

     <?php    
            $action = $_POST['subscribePage']; 
            $formData = json_decode($_POST['formData']); 
            $fname = $formData->{'fname'}; 
            $lname = $formData->{'lname'}; 
            $busname = $formData->{'busname'}; 
            $bustype = $formData->{'bustype'}; 
            $selectmenu = $formData->{'selectmenu'};

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>
<!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Verification</title>    
     <link href="style.css" rel="stylesheet" type="text/css">

    <!--For JQuery mobile UI widgets -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

    </head>

    <body>

    <div data-role="page" id="subscribePage">

    <div data-role="header">
            <h1>Verification</h1>
    </div><!-- /header -->

    <!-- Start Here: Web Form tutorial -->
    <div role="main" class="ui-content" id="subscribeBox">

    <h2><span class="thin">Create A Verified</span> XXXX <span class="thin">Account</span></h2>
        <p>Please fill out the following information to receive our verification. Verification should take less than 24 hours.</p>

    <form id="subscribeContent" class="subscribeForm" data-ajax="false" >
    <!-- name fields here -->
    <div data-role="fieldcontain">
      <input id="fname" type="text" placeholder="First Name*" Name="fname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="lname" type="text" placeholder="Last Name*" name="lname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="busname" name="busname" placeholder="Business/Organization Name*" required><br>
    <div data-role="fieldcontain">

    <!-- Other form fields here.... -->

    <!-- radio buttons here -->
    <div data-role="fieldcontain">
      <fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Option</legend>
        <input type="radio" class="bustype" name="bustype" id="radio1" value="Local Business/Organization" />
        <label for="local">Local Business/Organization</label>
        <input type="radio" class="bustype" name="bustype" id="radio2" value="Worldwide Brand" />
        <label for="worldwide">Worldwide Brand</label>
      </fieldset>
    </div>

    <!-- dynamic fields here -->
    <div data-role="fieldcontain">
      <label for="selectmenu" class="select">Options:</label>
      <select name="selectmenu" id="selectmenu">


        <option value="bank">Bank</option>
        <option value="car_dealer">Car Dealer</option>
        <option value="car_rental">Car Rental</option>
        <option value="car_repair">Car Repair</option>

        <!-- Other SelectMenu options here -->
        </select>
    </div>
    <!-- submit button here -->
        <input id="submit" type="submit" value="Send">

    </form>


    <div data-role="footer">
            <h4>XXXX App</h4>
    </div> <!-- /main --> 
    </div> <!-- /header --> 
    </div> <!-- /page -->
    <script src="postScript.js"></script>
    </body>
    </html>
 <?php    
            //$action = $_POST['action'];             
            $fname = $_POST['fname']; 
            $lname = $_POST['lname']; 
            $busname = $_POST['busname']; 
            $bustype = $_POST['bustype']; 
            $selectmenu = $_POST['selectmenu'];

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>

验证
验证
创建已验证的XXXX帐户
请填写以下信息以接收我们的验证。验证应在24小时内完成




选项 本地业务/组织 世界品牌 选项: 银行 汽车经销商 汽车租赁 汽车修理 XXXX应用程序
您的所有脚本中都存在问题。请尝试以下操作:

webformcomplete.php

     <?php    
            $action = $_POST['subscribePage']; 
            $formData = json_decode($_POST['formData']); 
            $fname = $formData->{'fname'}; 
            $lname = $formData->{'lname'}; 
            $busname = $formData->{'busname'}; 
            $bustype = $formData->{'bustype'}; 
            $selectmenu = $formData->{'selectmenu'};

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>
<!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Verification</title>    
     <link href="style.css" rel="stylesheet" type="text/css">

    <!--For JQuery mobile UI widgets -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

    </head>

    <body>

    <div data-role="page" id="subscribePage">

    <div data-role="header">
            <h1>Verification</h1>
    </div><!-- /header -->

    <!-- Start Here: Web Form tutorial -->
    <div role="main" class="ui-content" id="subscribeBox">

    <h2><span class="thin">Create A Verified</span> XXXX <span class="thin">Account</span></h2>
        <p>Please fill out the following information to receive our verification. Verification should take less than 24 hours.</p>

    <form id="subscribeContent" class="subscribeForm" data-ajax="false" >
    <!-- name fields here -->
    <div data-role="fieldcontain">
      <input id="fname" type="text" placeholder="First Name*" Name="fname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="lname" type="text" placeholder="Last Name*" name="lname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="busname" name="busname" placeholder="Business/Organization Name*" required><br>
    <div data-role="fieldcontain">

    <!-- Other form fields here.... -->

    <!-- radio buttons here -->
    <div data-role="fieldcontain">
      <fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Option</legend>
        <input type="radio" class="bustype" name="bustype" id="radio1" value="Local Business/Organization" />
        <label for="local">Local Business/Organization</label>
        <input type="radio" class="bustype" name="bustype" id="radio2" value="Worldwide Brand" />
        <label for="worldwide">Worldwide Brand</label>
      </fieldset>
    </div>

    <!-- dynamic fields here -->
    <div data-role="fieldcontain">
      <label for="selectmenu" class="select">Options:</label>
      <select name="selectmenu" id="selectmenu">


        <option value="bank">Bank</option>
        <option value="car_dealer">Car Dealer</option>
        <option value="car_rental">Car Rental</option>
        <option value="car_repair">Car Repair</option>

        <!-- Other SelectMenu options here -->
        </select>
    </div>
    <!-- submit button here -->
        <input id="submit" type="submit" value="Send">

    </form>


    <div data-role="footer">
            <h4>XXXX App</h4>
    </div> <!-- /main --> 
    </div> <!-- /header --> 
    </div> <!-- /page -->
    <script src="postScript.js"></script>
    </body>
    </html>
 <?php    
            //$action = $_POST['action'];             
            $fname = $_POST['fname']; 
            $lname = $_POST['lname']; 
            $busname = $_POST['busname']; 
            $bustype = $_POST['bustype']; 
            $selectmenu = $_POST['selectmenu'];

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>
mailer.php

     <?php    
            $action = $_POST['subscribePage']; 
            $formData = json_decode($_POST['formData']); 
            $fname = $formData->{'fname'}; 
            $lname = $formData->{'lname'}; 
            $busname = $formData->{'busname'}; 
            $bustype = $formData->{'bustype'}; 
            $selectmenu = $formData->{'selectmenu'};

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>
<!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Verification</title>    
     <link href="style.css" rel="stylesheet" type="text/css">

    <!--For JQuery mobile UI widgets -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

    </head>

    <body>

    <div data-role="page" id="subscribePage">

    <div data-role="header">
            <h1>Verification</h1>
    </div><!-- /header -->

    <!-- Start Here: Web Form tutorial -->
    <div role="main" class="ui-content" id="subscribeBox">

    <h2><span class="thin">Create A Verified</span> XXXX <span class="thin">Account</span></h2>
        <p>Please fill out the following information to receive our verification. Verification should take less than 24 hours.</p>

    <form id="subscribeContent" class="subscribeForm" data-ajax="false" >
    <!-- name fields here -->
    <div data-role="fieldcontain">
      <input id="fname" type="text" placeholder="First Name*" Name="fname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="lname" type="text" placeholder="Last Name*" name="lname" required><br>
    </div>
    <div data-role="fieldcontain">
        <input id="busname" name="busname" placeholder="Business/Organization Name*" required><br>
    <div data-role="fieldcontain">

    <!-- Other form fields here.... -->

    <!-- radio buttons here -->
    <div data-role="fieldcontain">
      <fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Option</legend>
        <input type="radio" class="bustype" name="bustype" id="radio1" value="Local Business/Organization" />
        <label for="local">Local Business/Organization</label>
        <input type="radio" class="bustype" name="bustype" id="radio2" value="Worldwide Brand" />
        <label for="worldwide">Worldwide Brand</label>
      </fieldset>
    </div>

    <!-- dynamic fields here -->
    <div data-role="fieldcontain">
      <label for="selectmenu" class="select">Options:</label>
      <select name="selectmenu" id="selectmenu">


        <option value="bank">Bank</option>
        <option value="car_dealer">Car Dealer</option>
        <option value="car_rental">Car Rental</option>
        <option value="car_repair">Car Repair</option>

        <!-- Other SelectMenu options here -->
        </select>
    </div>
    <!-- submit button here -->
        <input id="submit" type="submit" value="Send">

    </form>


    <div data-role="footer">
            <h4>XXXX App</h4>
    </div> <!-- /main --> 
    </div> <!-- /header --> 
    </div> <!-- /page -->
    <script src="postScript.js"></script>
    </body>
    </html>
 <?php    
            //$action = $_POST['action'];             
            $fname = $_POST['fname']; 
            $lname = $_POST['lname']; 
            $busname = $_POST['busname']; 
            $bustype = $_POST['bustype']; 
            $selectmenu = $_POST['selectmenu'];

            $sendgrid = new SendGrid("[-----API-KEY-----]");
            $email    = new SendGrid\Email();

            { $body = "{$fname} {$lname} \n{$busname} \n{$bustype}  \n{$selectmenu}"; }


            $email->addTo("admin@my-privatedomain.com") 
                ->setFrom("admin@my-privatedomain.com") // for testing purposes
                ->setSubject("Verification Request")
                ->setHtml($body);

            $sendgrid->send($email);
        ?>

还要确保文件中包含了SendGrid库,并且设置了有效的API-KEY。