I submitted this article because I found it to be of great use and it does a good job of supporting all my form emailing needs. If you find it useful, then great! :)
It's quite simple to use, all you need to do is the following:
- The sendmail.asp file.
- An HTML page with a form that needs to be emailed (making sure certain required hidden fields are included).
- A thanks page to redirect to when the mail send is complete.
- An optional email template to define how the form contents should be formatted in the email that is sent.
The script supports plain text and HTML email formats. If you want to send an HTML email, you must create an email template first. You can use a plain text email template instead if you like, and if you prefer not to use HTML but still want to make sure the email is formatted nicely.
In your email template, you should put placeholders for each form element submitted. The placeholders should be formatted like this: [$form-field-name$]. For example, if you have a text field called "surname", your placeholder in the template should read: [$surname$]. The zip file for this article contains a sample email template for you to look at.
A set of hidden fields is required in your form so that the sendmail script knows what to do with the contents of the form, and where and how to send it. If applicable, you can replace some of the hidden fields with real fields to allow users to customize, for example, whom to send the mail to, or what the subject line in the email should be. The fields that the sendmail script understands are:
redirect - required
The URL to redirect to when the mail has been sent.
mailto - required
The email address of the recipient (separate multiple recipients with commas).
The email address of the cc recipient (separate multiple recipients with commas).
The email address of the bcc recipient (separate multiple recipients with commas).
mailfrom - required
The email address of the sender.
subject - Required, if no email template is specified.
The subject line of the email.
An optional message to include before the contents of the form in the email. Only used if no email template is specified.
A relative path to a plain text or HTML file to use as an email template.
Must be "yes" or "no". If yes, the email will be sent as an HTML email, otherwise, it'll be sent as a plain-text email.
Must be "yes" or "no". If yes, the email will not be sent. Instead, the email will be written to the screen, with no redirection to the thanks page specified by the "redirect" field. This should be used to test the form and the email templates to make sure you are happy with the results.
Make sure that the form points to the sendmail.asp file, and that the method is set to "
<form action="sendmail.asp" method="post">
The included zip file contains a sample form with validation, a sample email template, thanks page and of course, the script.
- 18th November, 2003
- 15th March, 2006
- A CDO version of the script has now been included that should work on most new servers where the old one was failing. It also has a feature to hide email addresses from the hidden fields if desired. Just open the ASP file for a detailed explanation.