Hướng dẫn cài đặt đơn hàng thông qua Google Form

Hướng dẫn cài đặt đơn hàng thông qua Google Form

Cập nhật ngày Bởi

Hướng dẫn cài đặt đơn hàng hiện trên bảng tính của google và thông báo qua email ngay lập tức. Thủ thuật này rất đơn giản thôi, các bạn xem video nhé.


Link video youtube: Hướng dẫn cài google form lên website

Code sử dụng trong video


Code 1: Chỉ gửi email tới một địa chỉ cố định (ví dụ: admin)

function sendFormResponse(e) {
  const config = {
    toEmail: "giaodienblog@gmail.com", // Email cố định duy nhất nhận email
    subject: "Tư vấn Mua hàng",
    styles: {
      container: "font-family: Arial, sans-serif; max-width: 600px; margin: 20px auto; background-color: #f9f9f9; padding: 15px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);",
      header: "color: #1a73e8; margin: 0 0 15px; font-size: 22px; text-align: center;",
      content: "background-color: #fff; padding: 10px; border-radius: 5px; border: 1px solid #eee;",
      row: "display: flex; align-items: center; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed #ddd;",
      label: "color: #1a73e8; font-weight: bold; font-size: 14px; min-width: 120px;",
      value: "color: #333; font-size: 14px; flex: 1; word-wrap: break-word;",
      footer: "color: #777; font-size: 11px; text-align: center; margin-top: 15px;"
    }
  };

  const rows = Object.entries(e.namedValues).filter(([_, value]) => value?.toString().trim() !== "").map(([key, value]) => `
      <div style="${config.styles.row}">
        <span style="${config.styles.label}">${key}:</span>
        <span style="${config.styles.value}">${value}</span>
      </div>
    `).join("");
  const message = `
    <html>
      <body style="${config.styles.container}">
        <h2 style="${config.styles.header}">${config.subject}</h2>
        <div style="${config.styles.content}">${rows}</div>
        <p style="${config.styles.footer}">Email được gửi từ hệ thống tự động - Vui lòng không trả lời trực tiếp</p>
      </body>
    </html>
  `;
  try {
    MailApp.sendEmail({
      to: config.toEmail, 
      subject: config.subject,
      htmlBody: message
    });
  } catch (error) {
    Logger.log(`Lỗi gửi email: ${error.message}`);
  }
}


Code 2: Gửi email tới hai địa chỉ: một email cố định (admin) và email do khách hàng điền trong biểu mẫu.

Yêu cầu trong form phải có câu hỏi Email và bắt buộc đặt tên duy nhất là "Email" cho câu hỏi đó
function sendFormResponse(e) {
  const config = {
    toEmail: "giaodienblog@gmail.com",
    subject: "Tư vấn Mua hàng",
    styles: {
      container: "font-family: Arial, sans-serif; max-width: 600px; margin: 20px auto; background-color: #f9f9f9; padding: 15px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);",
      header: "color: #1a73e8; margin: 0 0 15px; font-size: 22px; text-align: center;",
      content: "background-color: #fff; padding: 10px; border-radius: 5px; border: 1px solid #eee;",
      row: "display: flex; align-items: center; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed #ddd;",
      label: "color: #1a73e8; font-weight: bold; font-size: 14px; min-width: 120px;",
      value: "color: #333; font-size: 14px; flex: 1; word-wrap: break-word;",
      footer: "color: #777; font-size: 11px; text-align: center; margin-top: 15px;"
    }
  };
  const bccEmail = e.namedValues["Email"]?.toString() || "";
  const rows = Object.entries(e.namedValues).filter(([_, value]) => value?.toString().trim() !== "").map(([key, value]) => `
      <div style="${config.styles.row}">
        <span style="${config.styles.label}">${key}:</span>
        <span style="${config.styles.value}">${value}</span>
      </div>
    `).join("");
  const message = `
    <html>
      <body style="${config.styles.container}">
        <h2 style="${config.styles.header}">${config.subject}</h2>
        <div style="${config.styles.content}">${rows}</div>
        <p style="${config.styles.footer}">Email được gửi từ hệ thống tự động - Vui lòng không trả lời trực tiếp</p>
      </body>
    </html>
  `;
  try {
    MailApp.sendEmail({
      to: config.toEmail,
      bcc: bccEmail,
      subject: config.subject,
      htmlBody: message
    });
  } catch (error) {
    Logger.log(`Lỗi gửi email: ${error.message}`);
  }
}

Nhận xét

Dịch vụ SMM
×