duan198727 2017-07-21 06:08
浏览 42

如何使用PHP将表单数据传递和存储到谷歌电子表格

Actually i created simple form,this form data how to pass & store google spreadsheet using php,so i'm posting the data form to post-enquiry.php file i have to added my google spreadsheet code is else part plsae check and let me now please any one help me. Below are the my HTML form code:

    <form method="post" class="enquiryForm" id="input-form" action="post-enquiry.php">
            <input type="text" style="position:absolute; top:-99999px; left:-9999px;" name="user_name"  value=""> 
            <input type="text" name="Name" id="quick_name" placeholder="Your Name" required="required" class="wid50 alpha-only" />
            <input type="email" name="Email" id="quick_email" placeholder="Your Email" required="required" class="wid50" />
            <input type="mobile" name="Mobile" id="quick_phone" placeholder="Your Phone Number" required="required" class="wid50 phone-number" maxlength="12" />
            <input type="location" name="location" id="quick_location" placeholder="Your location" required="required" class="wid50 alpha-only"/>           
            <textarea rows="5" class="wid100 textarea" placeholder="Tell Us Your Needs" id="desc" name="Subject"></textarea>
            <input type="submit" value="Submit" id="submit" name="submit" class="inputSubmit" />
        </form> 

Below the My php code:

<?php if(isset($_POST['submit'])){
  error_reporting(0);
  include("mailer/class.phpmailer.php");
  $name         = $_POST['Name'];
  $email        = $_POST['Email'];
  $mobile       = $_POST['Mobile'];
  $country      = $_POST['location'];
  $description    = $_POST['Subject'];
  $contact_name ="Sir / Madam";
  $message = "";

  $subject_thankyou = "Requesting For Quote";
  $mail = new PHPMailer;
  $mail->IsSMTP(); // enable SMTP
  $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth  = true;  // authentication enabled

  $mail->Host     = "smtp.sendgrid.net";/*Specify main and backup SMTP servers*/
  $mail->Port     = 25;
  $mail->SMTPAuth = true;/*Enable SMTP authentication*/
  $mail->Username = "";/*SMTP username*/
  $mail->Password = "";/*SMTP password*/

  $mail->setFrom('tghdrtgtr', $name);
  $mail->addAddress($email , 'rthtrhthtr');
  $mail->isHTML(true);

  $mail->Subject = $subject_thankyou;
  $mail->Body    = $message_thankyou;
  $mail->AltBody = $subject_thankyou;

  $mail->send();

  $subject = 'Your general enquiry'; 

  $email_header ='<html style="color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); max-width: 575px; line-height: 18px; font-size: 12px; font-family: Arial, Helvetica, sans-serif;">
                    <head>
                      <meta name="viewport" content="width=device-width" />
                      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                  </head>
                  <body bgcolor="#FFFFFF" text="#000000"  style="color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); max-width: 575px; line-height: 18px; font-size: 12px; font-family: Arial, Helvetica, sans-serif;">
                  <table style="font-family:Helvetica,Arial,sans-serif;background:#EFEDED;" cellpadding="0" cellspacing="0" bgcolor="#EFEDED" border="0" width="100%">
                  <tbody>
                  <tr>
                  <td align="center">
                  <table width="96%" cellpadding="0" cellspacing="0"border="0">
                  <tbody>              
                  <tr>
                  <td style="border-top:5px solid #1e96d3; background:#fff;margin:0; padding:20px; border-spacing:0px;">';

  $email_footer = '</td>
                    </tr>
                    <tr>
                    <td style="margin:0; padding:15px 0;">
                    <table style="font-family:Arial, Helvetica,sans-serif;font-size:11px;color:#999999;" cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tbody> 
                    <tr>
                    </td>
                    </tr>
                    <tr>
                    <td style="font-family:Arial, Helvetica,sans-serif; margin:0; font-size:11px; padding:8px 0 0 0;">
                    </td>
                    </tr>                
                    </tbody>
                    </table>
                    </td>
                    </tr>
                    </tbody>
                    </table>
                    </td>
                    </tr>              
                    </tbody>
                    </table>
                    </body>
                    </html>';

    $body = $email_header.
        '<table width="100%" cellpadding="0" cellspacing="0">
          <tr>
            <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
            <p style="font-size:14px; color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-weight: bold; line-height: 1.5em; margin: 0px; padding: 0.4em; text-align: left;">
              '.$subject.'
              </p>
              </td>
              </tr>
              <tr>
              <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
              <p style="color:#000; font-size:13px; margin:0; font-family:Arial, Helvetica,sans-serif;">
              <strong>
              Dear '.$contact_name.',
              </strong>
              <br>
              </p>
              </td>
              </tr>                     
              <tr>
              <td style="margin:0; padding:0 0 5px 0;">
              <p style="font-size:13px; background-color: rgb(234, 234, 234); color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-weight: bold; line-height: 1.5em; margin: 0px; padding: 0.4em; text-align: left;">
              Details:
              </p>
              </td>
              </tr>
              <tr>
              <td style="margin:0; padding:0px 0px 15px 0px; border-spacing:0px;">
              <table style="font-family:Helvetica,Arial,sans-serif; font-size:12px; font-weight:bold; margin-top:10px; width:100%">
              <tbody>
              <tr>
              <td style="width:120px; padding:4px 0;">
              Name
              </td>  
              <td style="padding-right:10px;">
              :
              </td>
              <td style="font-weight:normal;">
              '.$name.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Email Address
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$email.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Phone Number
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$mobile.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Country
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$country.'
              </td>
              </tr>
              <tr>
              <td style="padding:4px 0;">
              Subject
              </td>
              <td>
              :
              </td>
              <td style="font-weight:normal;">
              '.$description.'
              </td>
              </tr>
              </tbody>
              </table>
              </td>
              </tr>
              </table>'
              .$email_footer;
              //print_r($body);die;
    $message .= $body;
    $mail = new PHPMailer;
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth  = true;  // authentication enabled

    $mail->Host     = "smtp.sendgrid.net";/*Specify main and backup SMTP servers*/
    $mail->Port     = 25;
    $mail->SMTPAuth = true;/*Enable SMTP authentication*/
    $mail->Username = "eerrerer";/*SMTP username*/
    $mail->Password = "feredfe";/*SMTP password*/

    $mail->setFrom($email, 'Thank You');
    $mail->addAddress('frerfer' , 'dfgrgrg');
    $mail->addBCC('hddhfdhfg');
    $mail->isHTML(true);

    $mail->Subject = $subject;
    $mail->Body    = $message;
    $mail->AltBody = $subject;
    // $mail->send();
  if(!$mail->send()) {
    ?>
    <script type="text/javascript">
      window.alert("mail not sent sucssfully!");
    </script>
    <?php
  }
  else{
//my google spread sheet code
//echo "ewfueif";
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.8.1/library");
include_once("Google_Spreadsheet.php");
$u = "mygmail@gmail.com";//my spreadsheet user name
$p = "sd2323";//my spreadsheet user id
$ss = new Google_Spreadsheet($u,$p);
$ss->useSpreadsheet("FLORET12");
// if not setting worksheet, "Sheet1" is assumed
// $ss->useWorksheet("worksheetName");
$row = array("name" => $name, "email" => $email, "phone" => $mobile, "Location" => $country, "Description" => $description);

if ($ss->addRow($row)) echo "Form data successfully stored using Google Spreadsheet";

else echo "Error, unable to store spreadsheet data";
//header("location:thanks.php");
  }
}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?