我是javascript的新手任何帮助将不胜感激。
的更新
到目前为止的步骤:
1.)创建Wixsite并形成
2.)创建Mailjet帐户和注册的电子邮件地址作为批准的发件人
3.)我有我的API密钥和我的秘密API密钥
4.)我有2个后端.js文件
_a。)mailjet.js
_b。)email.js
以下代码位于我的mailjet.js中:
import wixFetch from 'wix-fetch'; export function sendWithMailjet(MJ_APIKEY_PUBLIC, MJ_APIKEY_PRIVATE, FromEmail, FromName, Recipients, subject, content) {
var headers = {
"Authorization": "Basic" + btoa(MJ_APIKEY_PUBLIC + ":" + MJ_APIKEY_PRIVATE),
"Content-Type": "application/json"
};
var body = {
"FromEmail": FromEmail,
"FromName": FromName,
"Subject": subject,
"Text-part": content,
"Recipients": [{
"Email": Recipients
}
]
};
return fetch('"https://api.mailjet.com/v3/send', {
method: 'POST',
headers: headers,
body: JSON.stringify(body)
})
.then((res) => {
if (res.status === 200)
return 'Email was sent';
else {
var headersString = '';
res.headers.forEach((value, name) => headersString += `${name}: ${value}\n`);
return res.text()
.then((bodyText) => {
return Promise.reject(new Error('Failed to send email.\n' +
`Status: ${res.status}\n` +
headersString +
bodyText));
})
}
});}
以下代码位于我的email.js
中 import {sendWithMailjet} from 'backend/mailjet.js'; export function sendEmail(FromEmail, FromName, Recipients, subject, content) {
const MJ_APIKEY_PUBLIC = 'myapipubliccode'; //mailjet API key
const MJ_APIKEY_PRIVATE = 'myapisecretcode'; //mailjet secret key
FromEmail = 'jparks@jonescarter.com';
FromName = '"James Parks" <jparks@jonescarter.com>';
return sendWithMailjet(MJ_APIKEY_PUBLIC, MJ_APIKEY_PRIVATE, FromEmail, FromName, Recipients, subject, content);
}
在我的表单页面上,我有以下代码:
import {sendEmail} from 'backend/email';
function SendClientEmail() {
const Subject = `New Submission from ${$w("#input3").value}`;
var content = `Name: ${$w("#input1").value}
\rEmail: ${$w("#input3").value}
\rFirstName: ${$w("#input1").value}
\rLastName: ${$w("#input2").value}
\rUserEmail: ${$w("#input3").value}
\rLocation: ${$w("#dropdown1").value}
\rPractice: ${$w("#dropdown2").value}
\rEventName: ${$w("#input4").value}
\rEventDate: ${$w("#datePicker1").value}
\rNeededBy: ${$w("#datePicker2").value}
\rQuantity: ${$w("#input5").value}
\rConfirm: ${$w("#dropdown3").value}
\rComments: ${$w("#textBox1").value}`;
var Recipients = `${$w("#input3").value}`;
//Make sure your from email address is validated in mailjet
sendEmail("FromEmail","FromName","Recipients",Subject, content)
.then(response => console.log(response));}
资源:
Wix如何发送电子邮件表单提交 - https://support.wix.com/en/article/how-to-send-an-email-on-form-submission
Mailjet for Developers - https://dev.mailjet.com/guides/?java#getting-started
再次,任何帮助将不胜感激。谢谢!