简体   繁体   中英

How to send html form to emails and google spreadsheet

I have my own form that sends a message to two e-mails. It's working.

I would like to save the same data from $_[POST] to google docs.

How I can send data to 2 emails and google spreadsheet ?

HTML code:

<form role="form" action="mail.php" method="post">
                <input type="text" name="company" id="company" class="form-control" placeholder="Your company">
                <input type="text" name="city" id="city" class="form-control" placeholder="City">
                <input type="text" name="person" id="person" class="form-control" placeholder="Name and surname">
                <input type="tel" name="phone" id="phone" class="form-control" placeholder="Phone number">
                <input type="email" name="email" id="email" class="form-control" placeholder="E-mail">
                <button type="submit" id="submit-btn" class="btn btn-default">Submit</button>
</form>

mail.php

<?php
$to      = 'user1@domain.com, user2@domain.com'; 
$subject = 'email from domain.com';
$company = $_POST['company'];
$city = $_POST['city'];
$person = $_POST['person'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = '<b>Message from website</b>'. "\r\n". "<br>" .
            '<b>Company:</b> '. $company . "\r\n". "<br>" .
            '<b>City:</b> '. $city . "\r\n". "<br>" .
            '<b>Person:</b> '. $person . "\r\n". "<br>" .
            '<b>Phone:</b> '. $phone . "\r\n" . "<br>" .
            '<b>Email:</b> '. $email . "\r\n";
$headers = 'From: ' . 'companies@domain.com' . "\r\n" .
    'Content-type: text/html; charset=utf-8';

mail($to, $subject, $message, $headers);

echo "Thank You, your email has been sent!<br />"; 
include 'success.php';
?>

I saw that I could create google form and replace my form, but that way I can only save data to spreadsheet, without sending emails.

How I can combine both functionality ?

Thanks for all tips.

See Google Sheets API . There click on the 'Protocol' tab.

There you find the information how to post a list row to a google sheet.

That does not fit to the question. How did you solve it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM