Making Email a Link to a Friend Work on a Locked Down Server PDF Print E-mail
Written by Fr. Robert Bower   
Wednesday, 21 July 2010 08:43

Some web hosts have a rule on their mail server that either the To or From email address must reside on the server for the php mail function to send an email from your php mail form.  It is a security feature that prevents the email server from being used to send spam.

In theory it is a great idea, however the Joomla's  Email a Link to a Friend feature will not work.  The email appears to be sent but actually is never sent unless the sender or recipient emails happens to be hosted on the site's email server.  The Email a Link to a Friend feature uses the email provided by the person filling out the form as the From email address, so in most cases the email is not sent on a server with the above rule.

The question is how to make the Email a Link to a Friend feature work?

To make the feature work the easiest technique is to have the email sent by an address residing on the server.

When I run into this situation, the first thing I do is create an email address such as This e-mail address is being protected from spambots. You need JavaScript enabled to view it  where yourserver.com is replaced domain of the website.  I use this email address to send the Email a Link to a Friend email.

The second step is to edit the php script the send the Email a Link to a Friend email to use the newly created email address rather then the form user's email.

The code that runs this feature is found in  the following file  /components/com_mailto/controller.php

Open the file with an online text editor and find the line

if ( JUtility::sendMail($from, $sender, $email, $subject, $body) !== true )

Change the line to

if ( JUtility::sendMail(' This e-mail address is being protected from spambots. You need JavaScript enabled to view it ', 'Donotreply', $email, $subject, $body) !== true )

where  This e-mail address is being protected from spambots. You need JavaScript enabled to view it is actually the email address you created to send the email.  Save the file and now the Email a Link to a Friend feature should work.  Please note when testing, if you try to use the Email a Link to a Friend feature back to back in quick succession the link will error out due to code preventing bots from sending mail in rapid succession and your rapid use of the feature is being interpreted as bot activity.

The recipient will receive  an email recommending the page sent by the email address you created and the person who filled out the form will have their name and email address listed in the body of the email.

Make sure you update the code if you update your Joomla site with a new version.

Last Updated on Thursday, 23 December 2010 08:32