如何通过&使用php将表格数据存储到谷歌电子表格

时间:2017-07-21 06:08:44

标签: php html

其实我创建了简单的表单,这个表单数据如何传递&使用php存储谷歌电子表格,所以我发布数据表格到post-enquiry.php文件我必须添加我的谷歌电子表格代码是否部分plsae检查,让我现在请任何人帮助我。 以下是我的HTML表单代码:

    <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 个答案:

没有答案