Kimler Sidebar Menu
Kimler Adventure Pages: Journal Entries
eMail Blog Entry
b2evo how-to: Blog Entry Sent via Email to a Friend
18-Oct-2007: Updated link for b2evolution versions 1.x or higher, which have a function name change - from "permalink()" to "permanent_url()".
This is a tough one to describe. Maybe it's better to come at it a different way. Say someone is visiting your site and likes a particular entry. "Hmmm," they might think, "Mary would really be interested in this." It's one thing to have that thought, quite another for them to be motivated enough to actually DO SOMETHING about it (fire off their email client, type an email, hunt down the permalink address to the specific entry, cut'n-paste it) ... that's a LOT of steps! Wouldn't it be convenient to have an "email a friend" link that does the same thing, but automatically and quickly? No email client, no cutting and pasting. Just click, add email addresses, maybe a short note and then BOOM - done!
If you think this might be a useful feature, then you've come to the right place! You can have a link like the one below that says, "Email Story", then pops up a form when clicked. No complicated b2evolution database changes or core file hacking. Three steps and you're done. You'll undoubtedly spend more time configuring the CSS to style the pop-up windows, than installing the thing. To get your very own 'email-this-entry' link, read on, brave blogger...
The Concept
The inspiration for this tool came, as it often does, from a question posted in the b2evolution forums. The fact that someone wanted this, led me to believe that such a tool hadn't been developed. Later, when someone asked the same question, I noticed that someone had posted a solution "CJ Send Page v2.0". I downloaded it, installed it and quickly realized a couple of things: The thing worked, but it wasn't optimized for b2evo, nor was it to my liking. First, the basic install didn't accommodate b2evolution (i.e. - the email link, by default, was index.php, not the particular blog entry). Second, it didn't notify the blog owner whenever someone emailed one of your entries.
So I modified it (several times, actually) and the latest solution is the one you see here. It is now significantly different from the original. I've left their credits in the PHP files, but have changed all external references to this site, because the original authors will not provide support for this enhanced version. The improvements I've made include the following:
• The off-the-shelf version uses three PHP files: "friend.php", "config.php" and "stylesheet.php". It's now all rolled into one - "friend.php", to keep the installation simple.
• It now supports individual b2evolution blog entries, via the permalink() function, rather than incorrectly pointing to just the site - "index.php".
• There's now a option to email you whenever someone uses the thing (you get all the juicy details, name, IP, email addresses and what they said about your blog entry).
• It has error-checking to help eliminate typos in the email or with field entry & they pop up in their respective form entry fields (without losing the data that has already been correctly entered). Nice.
• The style-sheet CSS has been expanded to control more elements. CSS variables have been eliminated, in favor of full control via normal, embedded style-sheets.
• The link rollover title attribute is uniquely designed for b2evo, showing as: [Send "Blog Title" to a Friend].
• The script degrades nicely if JavaScripting is turned OFF (instead of JavaScript pop-ups, the form opens in the current window and the JavaScript 'close window' buttons are replaced by link buttons that take the user back to the emailed blog entry). Accessible.
• Added 06-May-05 The pop up window allows for multiple email recipients & a succinct explanation of this feature has been added.
• Added 15-May-05 The ability to add a text-only copy of the actual blog entry, along with the email link, has been added. (With a spot reserved for sending HTML mail, though this is not yet functional).
• Added 11-Sep-05 A Spanish language version, with support for special character encoding and Spanish web display.
• Added 28-May-06 Anti-SPAM measures added. TABLES layout for forms pages have been converted to DIV/CSS layout and are valid to XHTML v1.0 (Strict) standards.
• Added 1-Sep-07 Graceful degradation when javascripting is disabled AND a visitor has elected to send a text-only copy of the post, in addition to the link, to a friend.
Wouldn't you know, after I finished, someone pointed to the fact that such a tool already exists. It's linked here as an option. I had a brief look at it. It works, but involves modifying the b2evo database (security issues), doesn't provide form error checking, doesn't email you when the someone uses it (though you probably could track usage via the database entries) & it cannot include a text copy of the actual entry. I'm glad that I didn't find this solution first, as I probably would have used it and not ended up with what I think is a superior solution.
3-Step Installation
The installation is pretty straightforward. There are two changes to your _main.php file. The first one is adding a one-line JavaScript function in the <head> area and the second involves placing the "mail-a-friend" link where you want it, on the page. In step three, you modify the friend.php file for your website specifics and uploaded it to a directory. (You might have to revisit step two, after step three, as the link must point to the friend.php file). That's it. If correctly configured, you should be up and running. Let's look at each step in more detail.
Step 1 - Defining the JavaScript function in the <head> area.
All you need to do for step 1 is insert the following code, somewhere between <head> and </head> in the _main.php for the skin(s) that you are using.
<script type="text/javascript"> function popUp(url){ window.open(url, "pop", "width = 650, height = 420, top = 90, left = 75, toolbar = 0, scrollbars = 1, resizable = 0") } </script>
It validates as XHTML(strict) and provides pop-up window size/placement. (You may wish to change these values, which are highlighted above. Just cut'n-paste the above code and you're ready to move on to step #2.
Step 2 - Adding the "Email Story" link.
Keeping the _main.php file for your skin(s) open, you simply cut'n-paste the following code wherever you want the link to show up. (I've tested the cut'n-paste method with my own blog ... it works).
<a href = "http://yoursite.com/where/youPut/friend.php?p=<?php echo $Item->ID ?>&id=<?php $Item -> permanent_url() ?>"
title = " Send "<?php $ttl = $Item -> title; $ttl = str_replace('"', '', $ttl); $ttl=strip_tags($ttl); echo $ttl; ?>" to a Friend " onclick = "javascript:popUp ( 'http://yoursite.com/where/youPut/friend.php?id=<?php $Item -> permanent_url() ?>&js=on&p=<?php echo $Item->ID ?>' ); return false" >Email Story</a>
Stuff highlighted in blue you must do, stuff in green is up to you.
Note: Older b2evolution installs (0.9.x or lower) will need to change the two function calls in the link from "permanent_url()" to "parmalink()".
The above code is a thing of beauty, if I do say so myself. :) By providing a link that includes an HREF, ONCLICK and a RETURN FALSE statement, this provides elegant degradation if a visitor has JavaScripting turned off (about 10% of folks do). Further, the "&js=on" tells the "friend.php" script whether JavaScripting is enabled. Another little trick was to make the <a> tag "title" attribute of the form [Send "Blog Title" to a Friend]. Because the "Blog Title" might have double quotes already, a bit of PHP code was inserted to collapse any double quotes, which keeps the browsers happy and avoids a possible triple-nested double quote situation. Ugly!
Enough tooting! You can change/add/modify to the <a> tag "title" attribute, if you like. Also, you can change the "Email Story" link text, or insert an <img> ... whatever you want to do to style it for your site. Oh, the link to the friend.php file should be fully-qualified or absolute (i.e., href="http://yoursite.com/etc/friend.php") and not relative (i.e., href="../../etc/friend.php").
Step 3 - Adding & Editing the "friend.php" script.
The third and last step, is to get the friend.php script file. You can download it in one of the following zipped flavors:
NOTE 17-Mar-2006: The script links below, have been pulled from our site. SPAMMERS have hacked the script and IF your version comes under attack, the script can be used to send SPAM. When this happens, a spammer can make it look like YOUR SITE is the spamming location. NOT a good thing! When I code a fix ... the links will return. (Fix Coded)
NOTE 28-May-2006: Anti-SPAM measures are now included. Downloads remain unlinked. Getting a copy is easy though - just REQUEST ONE! (an English version will be sent, unless you request a Spanish version).
• ENGLISH - (self-extracting exe, if you don't have winZip compressed zip, if you have winZip).
• SPANISH - (self-extracting exe, if you don't have winZip compressed zip, if you have winZip).
OKAY ... Now that you have downloaded the file, you need to edit it - changing the variables to match your particular site. Most of the configuration stuff is at the beginning of the file. Each field is commented, so I think (hope) it should be obvious what needs to be done. Please email me if you have any difficulty or suggestions about how to make it easier to do.
Once you have the configuration stuff done, all that remains is to upload it to your site and test it. It doesn't really matter which directory you upload the friend.php to, but keeping it close to your root directory will help shorten the link. To test, you should be able to click the "Email Story" link on your blog, then pull up the pop-up window ... fill in the blanks and BOOM ... you've got 3 emails generated. One to the person you've sent the link to, one to the person sending the link (as a reminder, for the record) and one to yourself (webmaster numero uno).
Once all the mechanics are working as expected, then you can set upon the task of customizing it for your site ... colors, border, background, text, etc. The CSS properties for the two pop-up windows are at the bottom of the 'friend.php' file. I've commented where they begin and where they end. The CSS in between is up to you.
That ends the basic install tutorial. I hope you find both the tutorial and the email code useful. Feedback (especially POSITIVE feedback) and, of course, coinage, is always appreciated and gets TOP priority! :D
The Future
This space is reserved for additions and further detail, as warranted by feedback. Right now, there are a couple comments that I'd like to make:
1) The 'friend.php' code is a tables-based construct that isn't XHTML(strict)-valid. I'd like to change that to a DIV-based construct that HAS been validated. Frankly, the thing works and that was the original goal, so it may be some time before it's changed. DONE (28-May-2006)
2) I'd really like to add an option (a check-box) that allows visitors to send the text-version of the blog entry, along with the link, in the email. The feedback I get about this will determine how rapidly this happens, if at all. DONE (15-May-2005)
Cheers, Scott
Version History
06-May-2005 - Multiple Email Addresses: I didn't figure that I'd be making modifications so soon, but Bill wanted to know if the recipient field accepted more than one email address. The answer is YES. Each email address just needs to be separated by a comma. I've made a new version (v050506) that has added a blurb, about this capability, on the pop-up window. I also fixed a couple of small typos and styling issues. The cut'n-paste code and the two ZIP files have been updated. Thanks for the feedback, Bill.
15-May-2005 - Text Copy of Blog Entry: This version (v050515) includes an option to include a text copy of the actual blog entry. If you are upgrading from an earlier version ... Step2: The link in _main.php has changed to add the (very important) post-ID number. Step3: The 'friend.php' file has been substantially modified. You will need to revisit these two steps (above). The contents of the article have been edited to reflect these latest changes and will be transparent to new users.
Note: Including the text copy of the blog entry requires that certain HTML elements be stripped. There is an array, further down in the code, that does this work, stripping certain HTML tags and converting various entities. You may wish to modify this array, depending on what tags and entities you commonly use in your blog. Use the existing entries as a guide for inputting regular expressions to search for the specific tag (or entity) and then replace the ones it finds with a corresponding 'regex' replace. (If you have difficulties, please email. Also .. whatever tags or entities you replace, let me know and I can include them in this version).
27-Jun-2005 - Minor Styling Changes: There are a variety of minor styling changes included in this version. Nothing major. If you have an earlier version - don't sweat it.
11-Sep-2005 - Spanish Version: Special thanks to Guillermo Casanova, of Venezuela, for his translation efforts. I had received a couple of queries, in the comments below, asking why the text-only version created undesirable output. One thing led to another and Guillermo was happy to translate the whole program.
14-Oct-2005 - HTML in Entry Title: Provides XHTML-valid code in the event XHTML tags are used in the blog entry title. (Only affects the "Adding the 'Email Story' link and is not necessary unless you add XHTML tags to your Post Title). Added code is in red.[1]
18-Dec-2005 - Phoenix Versions: Both the Spanish and English versions have been appended to provide support for both pre/post Phoenix release versions of b2evolution. (There is a new variable that you set to either "pre" or "post", which will automatically switch the code to work in the version of b2evolution you're using). Steps 1 & 2 (above) are unaffected, only Step 3 need be redone (download the new 18-Dec-2005 version).
28-May-2006 - Anti-SPAM & XHTML-valid: In March, the version we were running on our site was hacked by spammers. I have added some counter measures to strengthen the defenses. I also took some time to convert the tables layout to a non-tables layout, making sure that the each of the pages were written to XHTML v1.0 (Strict) standards.
1-Sep-2007 - Javascript degredation & text-only copy: Link ammended to provide graceful degradation for the situation where a visitor has javascripting disabled AND has requested a text-only copy.

















Nice work and thanks!
I'm glad you like it. Although, it's not a "hack" in the true sense (because no core files are modified). When you upgrade b2evo to a newer version, this feature will continue to function.
Great feature...I am passing it on to all of my friends.
Can you use multiple email addresses in the TO: box?
Thanks. That's a good question. And the answer is: YES, the recipient field WILL accept multiple email addresses. (Just need to use comma separators).
I don't know how many characters are allowed, but I'm sure there's some type of practical limit. (I tried 4 addresses and all were received OKAY).
I've made a new version of the friend.php file (v050506) that changes the pop-up window to succintly explain this capability. Be sure to cut'n-paste the code again (or download one of the ZIP files)!
Cheers,
Scott
Hey Glenn, where's yer missues at ? I used to live in Bielefeld (lol sp?.....hell it was 30 years ago
Avoid clouds that are sand coloured
¥
Right now it's nothing more than hopeful thinking, as I haven't even written one line of code.
Just seems to me that if text-only is doable, so should HTML ... but I might be full of malarkey (my wife thinks so)!
I wouldn't hold you're breath, but yes IF I finish ... I'll post here and on the b2 boards.
(before it was the picture zoom)
It turns out the designer dude who is designing the 'gateway' to this site is not at all conversant with b2 templates, so it has fallen on my incompetent self to try to make this thing look web worthy by the time I launch and I'm about losing my mind.
Thank you very much again.
Might I ask - if I insert the zoom script and this email magic in another 'skin' - will they still work as written? I have not been able to dress the skin up (custom) and I'll need to find another one.
The text version works well. Is there any chance of you releasing that before you complete the HTML version?
I've emailed you privately and look forward to helping you with your project. Don't worry, we'll get everything sorted out well before 'showtime'.
-Scott
That's not a bad idea, actually, because I have a couple of other projects that are on the front burner right now.
I suspect that an HTML version will be more difficult (and maybe not doable). Is this procrastination? ha.
I need to add a few more tweaks, but I'll try to get the text version up by Monday.
Cheers - Scott
Sooner is better than later
I would like to get it installed on my blog ASAP.
Thanks!
There some spanish (ISO 8859-1) characters from posts written in spanish, Scott configured for them and send it to me, and it`s works great!!
Sure in short time you get the "multilanguage" version!!!
Thanks and bye,
Pablo
Congratulations for your family, your excellent blog and this script (for now I don't include other scripts 'cause this is the first I'm trying).
I followed all your instructions and it works perfectly well except I have the same problem as the person from Argentina; I write with accented characters and when copying the blog content it sends an ugly text without accents but numbers instead.
What is the solution to that. Can you please tell me?
Best Regards
The "ugly numbers" are the ISO-8859-1 entity values (e.g., ¡
There is a SEARCH and REPLACE array in the friend.php script that you may amend to display the proper characters instead of the ISO-8859-1 entity values.
I have emailed files to both you and Pablo, with all *I think* the Spanish special chars.
One day, I hope to add a Spanish version for download, but for now, just email me if you want the Spanish search/replace function.
-Scott
Congratulations. It's great code! I got a problem, though. When trying to send the actual text of the post, I get:
"Fatal error: Call to undefined function: item_get_by_id() in /home/f/r/fraynelson.com/html/b2evocore/friend.php on line 111"
Any help, please?
Thank you for your time!
"/home/f/r/fraynelson.com/html"
Scott, thanks again!
Thanks.
friend_ev051218.zip -
thanks
I've recently pulled the script (both versions), as it has come under attack by spammers.
(Such an attack can make your site a SOURCE for SPAM).
When I code a fix, I'll put back the links.
-stk
I'd really like to add this feature.
I am aware that there is a security issue, but I am confidend that I can alter the script in such a way that it will be safe to use, or much harder to abuse.
I've sent you a copy of the script and modified this entry to reflect recent changes. (i.e. - anti-SPAM measures and XHTML-valid code changes)
Cheers,
-stk
All went well EXCEPT that my pop-up window was empty. There was no Form to fill out.
I already email Scott about it. I'm just entering here for documentation purposes for others in the feature. I'm sure Scott will post answer.
There is a line in the config file
// anti-SPAM (change the first '14' chars for your site)
$siteChar ='14'; // Check first 14 chars of site URL
$siteTxt ='http://YourS'; //[ite.com]
Basically: # of Chars for $siteTxt has to match # in $SiteChar=xx.
Thanks for the quick reply; and the hard work. It works now!
I'm glad you got it working and thanks for the positive feedback.
Cheers,
-stk
I never get this right . I did all 3 steps but keep getting the following back when i try to use it.
I originally used the name for the friend.php that you sent me in June but changed it to 'friend.php', but this error message keeps reflecting the URL before I corrected it. What am I doing wrong when you have a sec....
thanks
Ann
It's only called once, by the link in the _main.php file, so check there and make sure that it matches both the directory path, directory name(s) and filename.
The default is "friend.php", but you can use whatever you want.
Hope this helps.
-stk
I've updated the script to run faster. I've also simplified and strengthened the email validity checks.
I sent you a copy of the latest version (10-Jan-2007) via email.
Cheers,
-stk
I'm struggling to make it work though. I just get a blank window when I click the link. (It's the "Enviar por e-mail " link on my site).
Any idea what may be causing it? (I'm pretty much a total newbie at these things.)
I have emailed you to help get it going.
I'm sure we can sort it out.
Cheers,
-stk
Your help was amazing! I think this will be a great adition to my blog.
Thanks! Glad you got it working.
Can you send me the latest version of your script (for the send to friend)? It looks like precisely what I am looking for! Thanks!
I have responded via the email address you provided.
FYI - The code has been worked on recently (like last night).
-stk
Many thanks in advance.
I have responded via email.
I am sending a 31.jan.2007 edition. If you could translate it into Spanish, I can (again) offer such a version.
-stk
you are a fuggin ROCKING STAR!!!
thanks man. that last correction has it working. i'm
ready to go! i still want to change the colors of that
friend.php page, but i'll figure that out.
thanks a million
-mike
Cheers,
-stk
Mailed and thanks for the donation!
-stk
Pls send me a copy. It will be a big help for me and my bloggers.
Thank you.