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:

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).

canEmailToFriend()): ?>
__('Email this page to a Friend'); ?>

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

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