Recipe 7.8. Putting Additional Information in mailto Links


Problem

You need to pre-format an email message generated from a link on your web site.

Solution

Extend the mailto link to include values for the message subject, body, and additional recipients.

A basic mailto link on a web page creates a new email message in the user's default email application. It's a good idea to make the actual address the link, because that helps reinforce for the user what happens when she selects the link:

 <a href="mailto:address@domain.com">address@domain.com</a> 

You can create more complex links that fill in parts of the message. With Subject and Body, you can ensure at least some meaningful content in the email messages you receive from your site:

 <a href="mailto:address@domain.com?Subject=    web site%20comment&Body=Type%20your%20message%20here:">    address@domain.com</a> 

The characters %20 indicate a space in the encoded URL, though most browsers can handle an unencoded space.


You also can add additional recipients in the To:, Cc:, and Bcc: headers of the message by separating their addresses with commas:

 <a href="mailto:address@domain.com,another@domain.com&    Cc:afriend@domain.com&Bcc:someone@domain.com">address@domain.com</a> 

Discussion

Unprotected email addresses in web page code are like blood in the water for spam sharks. If you must use linked email addresses on your site (rather than an email form that hides actual addresses), be sure to read Recipe 9.11 for more information. Most of the protection techniques described in that Recipe will still allow you to add the additional information to your email links described in this Recipe. On the positive side, however, pre-formatting prevents email messages from your web site from being rejected as spam before they get to you. A preset email subject line can help spam filters recognize a message sent from your web site as legitimate.

See Also

Recipe 9.11 will help you use these techniques and still keep a clean inbox.



Web Site Cookbook.
Web Site Cookbook: Solutions & Examples for Building and Administering Your Web Site (Cookbooks (OReilly))
ISBN: 0596101090
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Doug Addison

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net