How can I use the Email ID field in Form A as the "To Address" of the send mail task, in From B?

How can I use the Email ID field in Form A as the "To Address" of the send mail task, in From B?

About the application

Assume you want visitors to subscribe to a newsletter through a subscription form and send mail to the e-mail ids of subscribed users. The application should also allow subscribers to unsubscribe from the news letter. The sample application Subscribe to Newsletter illustrates this scenario. The application has three forms:

Subscription Form :

The form to subscribe to the newsletter. It has the Name and e-mailid fields to enable visitors to subscribe to the newsletter by specifying their e-mail ids. There is also one hidden field "isUnsubscribed" to check the status of each subscription. This field is hidden when the form is loaded. The on add -> on load script given below, hides the isUnsubscribed field, when form is loaded.

on  add
{
on load
{
hide isUnsubscribed;
}
}

Send Mail Form :

This form is used by the owner to send mails to the subscribers mailing list. It has the Send decision check-box field which when set to "true" will send e-mails to the subscriber mailing list. This is achieved by adding on user input script to the Send field as given below.

Send
(
type = checkbox
defaultvalue = false
on user input
{
if (input.Send)
{
for each r in Subscription_Form [isUnsubscribed == false]
{
sendmail
(
To : r.EmailId
From : zoho.adminuserid
Subject : "Regarding subscription to our newsletter"
Message : "Your subscription is approved"
)
}
}
}

Code Explanation

if (input.Send) - The if statements will be executed if the Send decision check-box is set to true.

for each r in Subscription_Form [isUnsubscribed == false] - Here, isUnsubscribed is a Decision Check field and r is a variable that stores the records whose isUnsubscribed status is false.

sendmail - Send mail to the e-mail id specified in the row variable r.

Unsubscribe form

The form used to unsubscribe from the newsletter. This form contains the e-mailId field, using which the user unsubscribes from the newsletter. When a user submits his e-mailid, the on add -> on success script added to this form, updates the decision checkbox fieldisUnsubscribed in the Subscription form to true, as shown in the code given below:

on  add
{
on success
{
temp = Subscription_Form [EmailId == input.EmailId];
temp.isUnsubscribed = true;
}
}

Code Explanation:

temp = Subscription_Form [EmailId == input.EmailId];

-The above code will fetch records from the Subscription Form whose EmailId is equal to the EmailId specified in this form, and store it in a collection variable named temp.

temp.isUnsubscribed = true;

- The above code sets the isUnsubscribed field in the fetched record to true

Related Links

To install the application,

  1. Download the http://creator.zoho.com/exportScript.do?appid=89597000000135240&fileType=.ds&sharedBy=sampleapps
  2. Install the application to your account. Click here to learn how to install using the script file (.ds file)