My objective is my form, set the user entered email address value to appear as the sender of the email.
While my backend code ‘email.jsw’, the sender is using my own email address.
Example below in the Page Code form
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady(function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});
// Customize Your Email //
function sendFormData() {
const subject = [u]**Email Subject**[/u] ${$w("#EventName").value}
;
const body = <font size="3"> Hi ${$w("#name").value}, <br/>Details <br/>Name: ${$w("#name").value} <br/>E-mail: ${$w("#email").value} <br/>Phone Number: ${$w("#phone").value} </font>
;
const recipient = $w(" #email ").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
-----------------------------------------------------------------------------------
Example Back-End Code
// email.jsw //
import {sendWithService} from ‘backend/sendGrid’;export function sendEmail(subject, body) {const key = " YOUR_SENDGRID_API_KEY "; // Replace with your API key //
const sender = " myownemail@example.com "; // Sender email //
const recipient = " contact@example.com "; // Notification to yourself //
return sendWithService(key, sender, recipient, subject, body);}
-----------------------------------------------------------------------------------
Thanks in advance!