Notice: This mailto application and the examples below will only work on www.washington.edu. It will not work on other hosts, including other centrally-managed UW servers such as depts.washington.edu.
If you wish to implement a form on another web site which will send email, you need to make sure you have a script on the web server which will send the email.
We are unable to redistribute the code.
The mailto script allows you to allow people to mail comments to a specified address. It requires that the user enter an email address with a valid hostname after the @, and the mail which is sent will appear to come from that email address. For example, firstname.lastname@example.org.
If you have any questions which are not covered with this document, please send a message to the www-mgmt group.
Warning: this script has no means of verifying that what the end user types in for the email address or personal name is actually correct, even though it does try to make sure the hostname is a valid one. It is possible for users to falsify information or complete the form multiple times. However, an extra mail header is added to show from what host the browser is running (and, in some cases, the proxy cache being used if any). See the example mail below for what this extra header looks like.
At the bottom of this document are some hints for configuring mailto for special needs.
You can try using the example form which will send mail to a dummy user. This form uses a simple configuration file and response skeleton files:
Sample mail sent by the basic form example.
commentssection is implemented as a hidden field, because its use in this example is not mandatory.
=" instead of "
The files involved are:
reject.html.skelare the same as in the basic example.
Sample mail sent by the complex form example.
The attachment example shows:
The files involved are:
The two template files, accept.html.skel and reject.html.skel are the same as in the previous examples.
Your form must supply at least three fields with the names:
senderfor the email address of the person filling out the form. The mailto script will check that it looks like a reasonable email address, and that the hostname after the @ is a valid host.
sendernamefor the real name of the person filling out the form.
commentsfor the text of the mail message that gets sent. This field is normally set up as a
<input type="hidden" name="sendername" value="name"> <input type="text" name="optsendername" size=35 value="">The form's action should be the logical path to the configuration file. For example, in the basic example above, the form line is:
<form action="/webinfo/mailto/basic.mailto" method="post">
Note that the subject will always be either "Comments from the Web" or a subject which is configured in the config file. However, if your form contains a field named
subjectadd, the contents of that field are appended to the subject.
Entries are surrounded by tags embedded with
<> pairs. For example, to specify the destination for the message, you'd use:
<to>user@hostname</to>The only field which is required is the
</TO>field. It can contain only one email address. All mail sent by the mailto form will go to this user. Optional fields are:
reject.html.skelis used. Any line containing the string
--error--is removed and an appropriate error message is put in its place.
<reject_tmpl>when the user enters nothing in the
sendernamefield. The default string is
You did not supply your name
<reject_tmpl>when the user enters nothing in the
commentfield. The default is
Please complete the form
<reject_tmpl>when the user enters an email address in the
senderfield that has an invalid hostname. The default is
Your mail address contains an invalid hostname
Comments from the Web.
<xtra_headers> Requesting-Form: basic.mailto From-Host: www.washington.edu </xtra_headers>The headers must be valid RFC 822 headers, so you cannot use freeform text as extra headers.
You can also specify the separator by including that separator between colons. For example:
If no tag is specified, the field name is used.
If you wish to have some of these fields be required (as the comments, sender, and sendername field are) you need to prepend the field name with an asterisk (*). For example:
will make phone a required field. If the field is not present, the user will receive the same error message as if they didn't supply data for the comments field.
You may have an application where you need to require either one field or another, but not both. For example, you may wish to require either a phone number or an email address. To do this, you can define required groups by putting a group name before an asterisk. Only one field in the group is required, but an error will result if no fields in the group is provided. For example:
defines a required group named contact. This enforces that either phone or email (or both) is filled in. If both fields are left blank, then mailto will generate the same error as if the comments field were left blank.
If you wish to have an error message which is specific to a required field rather than the default Please complete the form you can specify one on the same line. For example:
*phone#You must enter a phone number
will display You must enter a phone number as the error message if the field is not filled.
You can also specify error messages for field groups. You only need to specify the message once; if you specify more than one message, the last one will be used.
The conditional consists of a form field name followed by a conditional test, followed by a string:
|var == "str"||form field var is equal to str|
|var != "str"||form field var is not equal to str|
|var > "str"||form field var is numerically greater than str|
|var >= "str"||form field var is numerically greater than or equal to str|
|var < "str"||form field var is numerically less than str|
|var <= "str"||form field var is numerically less than or equal to str|
|var =~ "str"||form field var matches the regular expression str|
|var !~ "str"||form field var does not match the regular expression str|
<prepend_fields> <if contactmethod == "Phone"> *phone email <elseif contactmethod == "Email"> phone *email <else> phone email </if> </prepend_fields>This code will require the phone field be filled in if the user chose "Phone" as the contact method, will require the email field be filed in if the user chose "Email" as the contact method, and will require neither in all other cases.
You may also specify an error message if the pattern does not match by putting it in quotes after the field name. For the box number example:
<validate box "Box numbers must be 35<i>dddd</i> where <i>d</i> is a digit">^35\d\d\d\d$</validate>
Which will display the error message:
Box numbers must be 35dddd where d is a digit
<form action="form.mailto" method="post" enctype="multipart/form-data">
form text here </form>
<input type="file" name="attachment">where the name matches what you put in the attachments section of your mailto config file.
You can specify multiple attachments in your form and mailto config file. If you do so, you may want to also put the fields in the prepend_fields section of the mailto config file, since that will show you which files were used for which fields of your form. By doing this, you can also require that the fields be filled (meaning that files were attached.)Warning: mailto cannot check whether attached files have viruses in them, so you should be very careful when you decide to allow users to attach files to your forms, as well as when opening attachments with your mail reader.
<html> <head> <title>Mail Acknowledgement</title> </head> <body> <h1>Mail Acknowledgement</h1> Thanks for trying out mailto! <p> Return to <a href="/webinfo/mailto/">mailto documentation</a> </body> </html>
If you wish to use data from the form in your confirmation file, you can do so by putting the field name between dashes. For example, the snippet of code:
Thank you, --sendername--, for trying out mailto!
would insert the sender's personal name into the confirmation page.
--error--it will remove that line and replace it with the appropriate error message. As with the confirmation skel, chtml markup may be used. An example file:
<html> <head> <title>Mailto Error</title> </head> <body> <h1>Mailto Error</h1> --error-- <p> Return to <a href="/webinfo/mailto/">mailto documentation</a> </body> </html>
Mailto was designed to work for most cases, but it can be configured to work in other applications.
If you don't wish to force the user to fill out a comment field, you can create a hidden comments field with a dummy value by including the following in your form:
<input type="hidden" name="comments" value="none">
The mail you receive will have a line which shows that the comment field is a value of
If you wish to require that the user select from a pop-up list, you can take advantage of the fact that the comments field is required, and make a list which looks like:
<select name="comments"> <option value="" selected>Select an option</option> <option value="first">First option</option> <option value="second">Second option</option> <option value="third">Third option</option> </select>
If the user does not make a selection, then mailto will return an error. You should also set the
MSG_NO_TEXT value in the config file to explain to the user that one of the options must be selected.
Some sites require that the user read an agreement statement and check a box verifying that it has been read. Again, the fact that the comments field is required can force the user to mark a checbox:
I agree with these terms. <input type="checkbox" name="comments" value="ok">
Because there is only one comments field, you cannot require both a checkbox and a selected pop-up value. Also, it is suggested that you change the
MSG_NO_TEXT field of the config file.
If your application does not require an email address, you can use a technique similar to making the comment field optional. Be sure that the dummy value is a valid email address, otherwise mailto will complain about it. For example, you could use:
<input type="hidden" name="sender" value="email@example.com">
Note that all mail will appear to be from the user firstname.lastname@example.org (or whatever value you happen to use.)
If the mail generated by mailto will be fed into a script which automatically processes each message, you can use the various configuration options to format the mail. For example, if the mail will be sent to an address which adds users to a mail list and requires the body to contain:
then you can add the following to your config file:
making sure there is a space between the colons. This will make the sender field to be written with subscribe instead of sender, and the text before the email address will be just a space.