How to Get Magento’s Email To A Friend URL

In the context of ever needing to get the “send an email to friend” url / link mark up from Magento in other scopes other than view.phtml (say a custom pthml file with layout specific needs that can be configured), here is what you do.

First we need to get our helpers / model / product like so:

<?php
    $_product = Mage::registry('current_product');
    $_helper = Mage::helper('catalog/product');
    $_this = Mage::registry('send_to_friend_model');
?>

Lastly we need to build up our markup with our above helpers / model and product. (Note very similar to how /app/design/frontend/YOUR SITE/YOUR THEME/templates/catelog/product/view.phtml build this link).

<?php if($_this->canEmailToFriend()): ?>
<a href="<?php echo $_helper->getEmailToFriendUrl($_product); ?>"><?php echo $_this->__('Email this page to a Friend'); ?></a>
<php endif; ?>

Note how we use $_this to test if we can display an email link so that we still have admin backend control over this. Also note we are passing $_product t the $_helper object’s getEmailToFriendUrl function; this give us our desired url for our href attribute. Optional target=”_blank” attribute can be added to the link to open in a new page if you like.

Devin R. Olsen

Devin R. Olsen

Located in Portland Oregon. I like to teach, share and dabble deep into the digital dark arts of web and game development.

More Posts

Follow Me:TwitterFacebookGoogle Plus

2 Responses to “How to Get Magento’s Email To A Friend URL”

  1. Devin R. Olsen ann says:

    Thank you, very useful!

  2. Devin R. Olsen Frank F says:

    Hi, haven’t tried the above code yet but do you know of a plug-in that will ‘reward’ the email sender for the product referral?
    Thanks

Leave a Reply