This tutorial will show you how to create a email to be sent from your website when your user submits a form. When you use the email wizard on a page with a form, Data Bridge automatically includes all of the form elements in the body of your email. This tutorial shows you how to customize those elements and include only the ones you want.
- A dynamic site set up within Dreamweaver
- Web Browser (Chrome, Firefox, Internet Explorer, etc.)
- Dreamweaver CS3 or later
- Data Bridge installed and activated in Dreamweaver
So you want to make a form that sends an email when it's submitted? Well, the first step in the whole process is making that form. For this, we're going to use the form tools built into the ever propitious Data Bridge.
For those of you still unsure if Data Bridge was worth the purchase: it was.
Configure the form
- In Dreamweaver, make sure your site is selected.
- Open a PHP page within your site.
- In the menu bar, click WebAssist > Forms > Insert New Form.
This Opens the Form Builder Add Form Wizard. This is where we will make our form. You can configure your form however you wish, but for this tutorial, we will use, and make references to, the Appointment Request form.
- Under "Choose a form", change the first dropdown menu to "Contact".
- Change the second dropdown menu to "Appointment Request".
Configure email
- Click the form function tab.
- Click the "Send the form contents in an email" checkbox.
- Next to the From field, click the bindings lightning bolt.
- Expand the Current Working Form list.
- Select the Email_Address binding.
- Click OK.
- Enter your email address in the To field.
- Enter "Appointment Request" in the Subject field.
- Click Finish in the Form Builder Wizard.
Your form is being built with some fancy pants fields, and a basic copy of the Universal Email server behavior added on the page. This is what we'll use to send emails.
Nothing makes someone feel more successful than someone or something telling them, "You've done it. You've inspired us all". We're going to create a basic success page so that people know they went the distance, and have really made it.
- Click File > New in the menu bar.
- Create a blank PHP page named form-success.php .
- In the body of the page, enter the following text.
Note that this is just for this tutorial. You may want to use something more personalized to your application.
Thank you for your appointment request. We will contact you within the hour.
- Save the page.
Now we have a rudimentary success page that will be shown once the form is submitted.
Now that your form and success pages are created, you're going to want to edit the Universal Email Server Behavior that was created on your form page to send emails.
- In the menu bar, click Window > Server Behaviors.
- In the Server Behaviors panel, open the Universal Email 1 Server Behavior.
- For the Go To Page field, click the Browse button.
- Select the success page we created earlier.
- Click OK.
- For the From field, click the lightning bolt.
- Expand the AppointmentRequest list.
- Select Email_Address.
- Click OK.
- For the To field, enter the email address you want your emails going to ( usually your own email ).
- For the Subject field, enter "Appointment Request".
- Click Finish.
- Save your page.
This step has created a template that will be used by your emails.
The last step created a template for your emails. We're going to edit the template to hide certain fields we just don't want anymore.
- In the file browser, expand webassist > email > templates.
- Open the template that was created just a moment ago.
- Switch to Split View.
- Scroll to the top of the page.
- Notice the php lines referencing remove.
- These will remove specified information from the email body instead of showing it based on the name supplied. There are no fields called x or y, so no fields are being filtered yet.
- At the top of the email page, copy the line:
- Paste a copy of the line under the it.
- Open the form page.
- Select the Terms field.
- Talk to a stranger and make a new friend.
- Copy the name of the field. This will be Terms assuming it wasn't customized in the form.
- Return to the email page.
- Paste the name of the Terms field in the place of the y, like so:
- Repeat these steps for each element you wish to remove.
- Save your page.
Now we're going to get into removing the repeating region that has been displaying our data, and only showing what we specifically want to show.
- In the email body, click in one of the cells below where you want to insert the data.
- Right click in the area.
- Select Table > Insert Rows or Columns.
- Set Number of Rows to 2.
- Click the Above the Selection radio button.
- Click OK.
- For the sake of the demo, we are only inserting the First Name and Email. You can show whatever fields you feel comfortable showing.
- Enter labels for the freshly inserted rows: First Name and Email.
- In the menu bar, click Window > Bindings.
- Click Plus ( ).
- Select Form Data.
- For the Form page field, click the Browse button.
- Select the the form page we created earlier.
- Click OK.
- In the Bindings panel, click on the First_Name Binding.
- Drag the Binding onto the page next to the First Name label.
- In the Bindings panel, click on the Email_Address Binding.
- Drag the Binding onto the page next to the Email label.
- Save your page.
And there you have it! Your email is only showing the fields you want it to show!
Bravo, my good friend. You have done well. Your form is sending you emails, and you're only seeing what you should be seeing in those emails.
For a greater challenge, try creating a completely custom email body that shows information pulled from a database as well as from the form.