Email Respondent a Certificate

Important Update to Custom Scripting

The CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!


  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

Need to create and email a personalized certificate to a respondent?

No problem!

After creating your own certificate image, upload the image to your Alchemer file library, copy this script and paste it into a custom script action, modify the highlighted sections, and test.

Check out this example survey!

OR

Add this survey to your account!

Estimated implementation and testing time: 30-60 minutes (Note: This time estimate does not include time required to create a certificate for your business or organization.)

This script uses the following custom scripting functions:

  • sgapiGetValue
  • sgapiHTMLTOPDF
  • sgapiEmailSend

The Script

In the script below, update the question ids for the name, course, and date, the link to the certificate background image, the css, and finally personalize the email.

Note: Make sure that your script is added to a survey page that follows the survey questions that are being used in the script.

%%name = sgapiGetValue(3);
%%course = sgapiGetValueLabel(4);
%%date = sgapiGetValue(5);

%%pdftemplate = '<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /></head>
<style>
.name {
  width:100%;
top: 290px;
display: block;
position: absolute;
font-size: 30pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;
}
.course {
  width:100%;
top: 420px;
display: block;
position: absolute;
font-size: 20pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;
}
.date {
  width:100%;
top: 510px;
display: block;
position: absolute;
font-size: 20pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;
}
</style>
<body style="margin:0; padding:0;">
<img src="http://surveygizmolibrary.s3.amazonaws.com/library/160589/BlankCertificate.png" style="height:770px; width:1097px;">
<span class="name">'.%%name.'</span>
<span class="course">'.%%course.'</span>
<span class="date">'.%%date.'</span></body>';

%%pdf = sgapiHTMLTOPDF(%%pdftemplate,true,false);

%%attachment['certificate.pdf'] = %%pdf;

%%htmlBody = "<b>Congratulations!</b><br/><br/>
You have completed the requirements for this training.<br/><br/>
Your personalized certificate is attached to this email.<br/><br/>
Domo arigato,<br/><br/><b>Mr. Roboto</b><br/>Styx Robotics</br>";

%%textbody = "Congratulations! 
You have completed the requirements for this training. 
Your personalized certificate is attached to this email.
Domo arigato, Mr. Roboto
Styx Robotics";

%%to = sgapiGetValue(6);
%%toName = sgapiGetValue(3);
%%from = "noreply@sgizmo.com";
%%fromName = "Mr. Roboto";
%%subject = "Certificate of Completion";
%%bcc = "notifications@sgizmo.com";
%%mailReplyTo = "noreply@sgizmo.com";
%%type = 'HTML';


sgapiEmailSend(%%to, %%toName, %%from, %%fromName, %%subject, %%textBody, %%htmlBody, %%bcc, %%mailReplyTo, %%type, %%attachment);

In the script above you will need to customize the variables highlighted in yellow in order to make the script work the way you'd like.

Required Customizations

The script below requires for us to update the question ids for the namecourse, and date, update the link to the certificate background image, update the css, and finally to personalize the email.

1. Create a quiz, form, or survey. The script will include the answers to 3 questions on the certificate; name, course, and date. You can use these same fields, or create your own.

2. Create a custom script action. Copy and paste the script above.

Update the variables as follows:

%%nameThis variable will indicate the question ID of the field for the name.

%%courseThis variable will indicate the question ID of the field for the course.

%%dateThis variable will indicate the question ID of the target Checkbox question.

%%to - This variable will indicate the question ID of the email address question. (This variable can not be renamed.)

%%toName - This variable will be the same question ID as %%name. (This variable can not be renamed.)

3. Create a certificate background image. You can download and use our certificate image as an example. Upload the certificate image as a .png file to the Alchemer file library. Replace the link to the certificate in the script with the link for the library.

Note: If you create a certificate that will position the name, course, and date in the same location, you can skip the NEXT STEP.

4. (OPTIONAL) Update the css where highlighted to position the name, course and date on the certificate background. If you created a modified version of the example certificate background you can skip this step. Otherwise, you may need to adjust the height of each field by adjusting the top positioning, the font-size of the text, and or the font color.

5. Personalize the email message. The sgapiEmailSend function has 11 parameters. All 11 parameters are required and must be present. You can not edit or modify the names of these parameters. The portions highlighted in green can be modified.

  • %%to - The recipient's email address.
  • %%toName - The recipient's name.
  • %%from - The sender's email address.
  • %%fromName - The sender's name.
  • %%subject - The subject line.
  • %%textBody - The plain text email body.
  • %%htmlBody - The html formatted email body.
  • %%bcc - bcc email address (can be an array).
  • %%mailReplyTo - Send replies to email address.
  • %%type - The type of email to send "text" or "html."
  • %%attachments - Email attachments (can be an array).

6. Test! Test! Test!

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for alchemer features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our professional Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!