April 16, 2004

Email to a Friend

Updated September 23, 2004

Movable Type comes with a built-in capability for allowing your weblog visitors to easily send an email with a link to your entry by filling out a simple form. The one small catch is that spammers can take advantage of cgi email programs like this to send out spam. Ben Trott has made a few adjustments to the MT code in the most recent releases to help protect against these types of spammers. But the easiest way to take advantage of this useful utility while at the same time protecting yourself is to change the name of the mt-send-entry.cgi script. (See the reasons why here) The following are instructions on how to include Email to a Friend on your MT weblog, first starting with changing the name of the script.

1. Change the name of the mt-send-entry.cgi script. In your CGI bin change the name of this file to something else, also ending with the .cgi suffix. For example, mt-send-an-email.cgi (use something else - a unique name).

2. Copy the Send Entry form into your Individual Entry Archive template. The Send Entry code can be found in the Movable Type documentation here. Change the name of the cgi file in the first line of the code to reflect the new name of your Send Email cgi. Example:

<form method="post" action="<$MTCGIPath$>mt-send-an-email.cgi">
<input type="hidden" name="entry_id" value="<$MTEntryID$>" />
<input type="hidden" name="_redirect" value="<$MTEntryLink archive_type="Individual"$>" />
Email this entry to:<br />
<input name="to" size="20" /><br /><br />
Your email address:<br />

<input name="from" size="20" /><br /><br />
Message (optional):<br />
<textarea name="message" rows="5" cols="20" wrap="virtual"></textarea><br /><br />
<input type="submit" value="Send" />
</form>

Place the code on your Individual Entry Archive template where you would like the form to be. If you place it in the main body and not in the sidebar, you may want to expand the column size in the message window from "20" to something greater, like "45".

Nest the code in the appropriate style div tags for your site. For example, on this site, I put the email form underneath the comments section. I want the email heading to look just like the comments heading which, in MT3, uses <h2></h2> tags.

<h2>Email to a friend</h2>


For default MT2.661, the heading tag would look like so:

<div class="comments-head">Email to a friend</div>
<div class="comments-body">

In the case of MT2.661, after the Send Entry code I insert a closing div tag.


3. Link to the Send Entry form. You may want to place a link in the Posted To line (at the end of each entry) directing readers to the form. To do this, first place an anchor tag right before the form, like so for MT3:

<a name="email"></a><h2>Email to a friend</h2>

or like so for MT2.661:

<a name="email"><div class="comments-head">Email to a friend</div> <div class="comments-body">

Then place a link on your Posted To line. On the Individual Entry Archive template the link would look like this:

<a href="#email">Email to a friend</a>

On the Main Index template, the link would look like this:

<a href="<$MTEntryPermalink$>#email">Email to a friend</a>

That's it! Save and rebuild your site.

Links:
MT-Mail-Entry - a plugin for emailing the entire entry, not just a link, includes a popup email form.


Has this tutorial been helpful? Please consider linking to Learning Movable Type at http://learningmovabletype.com/ . Thanks!

Posted by Elise Bauer on April 16, 2004 to Email
Comments(6) | Email to a friend | Printer-friendly version


Trackback

If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/214

Comments

Hi there, this is a very detail instruction, thanks.

Just a question, is there any way to include multiple email addresses in the field in "Email this entry to:", I would like to send a particular post to more than 1 email addresses, can that be done?

Hi ML,
I've noticed since the Ben Trott adjusted the code so it would be less likely to be abused by spammers that you can't send to multiple addresses anymore.

Hmm that is a waste, I need that functionality :(

anyway to hack the code? are u aware.

ML - Probably if you found an older version of MT. A good place to ask is on the MT Forums at http://www.movabletype.org/support/.

Hello Elise. Thank you so very much for this email an entry to a friend code. I waited so long for this.

I am eagerly waiting for the print this entry code for Movable Type 3.11.

You Rock!

Hi Gopal - you can use the Printer-friendly tutorial with MT 3.11. My example template and stylesheet work together. If used as is, they'll work in your MT3x blog. I do not plan to make changes to that tutorial in the near future. Good luck!

Comments are now closed for this entry.


Email to a friend

Email this article to:


Your email address:


Message (optional):