是否可以在Wix上使用自定义表单将图像发送到电子邮件地址,同时还可以使用sendGrid?

时间:2018-07-22 12:12:21

标签: forms sendgrid wixcode

我目前正在为Wix上的某人开发一个网站,并创建了一个包含2个字段的自定义用户输入表单,一个字段用于输入某人的姓名,另一个字段用于其电子邮件地址。该表单在同一页面上两次用于2个不同的事件,但是区别在于它们已连接到2个不同的数据集。

我已经使用sendGrid进行了设置,以便在提交表单时将其发送到输入通用“欢迎”电子邮件的电子邮件地址,但是我只想弄清楚如何发送文本行,显示在电子邮件正文中的图像。

下面是所有使用的代码:

email.jsw

// Filename: backend/email.jsw (web modules need to have a .jsw extension)

import {sendWithService} from 'backend/sendGrid';

export function sendEmail(subject, body) {
const key = "keygoeshere";
const sender = "emailgoeshere";
const recipient = "emailgoeshere";
return sendWithService(key, sender, recipient, subject, body);
}

export function sendEmailWithRecipient(subject, body, recipient) {
const key = "keygoeshere";
const sender = "emailgoeshere";
return sendWithService(key, sender, recipient, subject, body);
}

sendGrid.js

import {fetch} from 'wix-fetch';  

export function sendWithService(key, sender, recipient, subject, body) {
const url = "https://api.sendgrid.com/api/mail.send.json";

const headers = {
"Authorization": "Bearer " + key,
"Content-Type": "application/x-www-form-urlencoded"
};

const data = `from=${sender}&to=${recipient}&subject=${subject}&text=${body}`;

const request = {
"method": "post", 
"headers": headers, 
"body": data
};

return fetch(url, request).then(response => response.json());
}

页面代码:

// For full API documentation, including code examples, visit 
http://wix.to/94BuAAs
import {sendEmail, sendEmailWithRecipient} from 'backend/email';



$w.onReady(function () {
//TODO: write your page related code here...
$w("#dataset1").onAfterSave(sendFormData);
$w("#dataset2").onAfterSave(sendFormData2);
});

export function input1_dblClick(event, $w) {
//Add your code for this event here: 
}

function sendFormData() {
const subject = `New Wild Swimming Request`;
const body = `Hello ${$w("#input1").value}. Thank you for showing interest in Wild Swimming...`;
const recipient = $w("#input2").value;

sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response)); 

sendEmail(subject, body)
.then(response => console.log(response));
}

function sendFormData2() {
const subject = `New Plymphony Request`;
const body = `Hello ${$w("#input3").value}. Thank you for showing interest in Plymphony No.1, in Sea!...`;
const recipient = $w("#input4").value;

sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response)); 

sendEmail(subject, body)
.then(response => console.log(response));
}

我必须通过sendGrid和自定义表单来完成此操作,因为我需要为2个不同的事件填充2个单独的列表,无论出于何种原因,要么Wix不支持它,要么我找不到它,但是我无法创建2个单独的邮件列表,并且在提交表单后将2个表单发送给不同的电子邮件。

如果有一种方法可以使用Wix自己的形式进行操作,那么如果有人可以向我指出正确的方向,我将不胜感激,否则将不胜感激。谢谢

0 个答案:

没有答案