Follow this Blog!

Apr 30, 2012

f Comment

Joomla: How to Send Email When Someone Submits the Contact Form?

First take a look at my Joomla version
Amazon The following is information shown by going to Site -> System Information.

PHP Built OnLinux ip-10-1-2-3 4.5.6-7-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686
Database Version5.1.61-0ubuntu0.10.04.1
Database Collationutf8_general_ci
PHP Version5.3.2-1ubuntu4.14
Web ServerApache/2.2.14 (Ubuntu)
WebServer to PHP Interfaceapache2handler
Joomla! VersionJoomla! 2.5.4 Stable [ Ember ] 2-April-2012 14:00 GMT
Joomla! Platform VersionJoomla Platform 11.4.0 Stable [ Brian Kernighan ] 03-Jan-2012 00:00 GMT
User AgentMozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19

As you can see I use Joomla 2.5.4, but this tutorial applies to every previous version of Joomla. If not let me know!

The Problem
I am using Joomla's built-in contact form mechanism. The back-end administrator can create contacts and link them to a menu item so that when the menu item is selected information of each contact and a contact form are displayed. The front-end works great and looks something like this:

Joomla Built-in Contact Form Screenshot

The issue is when someone that visits my site fills out the form and clicks on 'Send Email' to submit the form the destination contact does NOT receive an email even though they are supposed to! Why is that? Did I do something wrong?? Is it a bug of Joomla's???

First and foremost, make sure your server has been set up to send out emails. Refer to my other tutorial - How to Send Emails with PHP - if you need help.

The Solution
This turns out to be a stupid setting that you need to set correctly in order for Joomla to send emails when the contact form has been submitted.

In the contact settings or menu item's settings for the contact you MUST select NO in the 'Custom Reply' field in the 'Mail Options' tab! Here's a screenshot. The red circle indicates the correct setting.

Joomla Menu Item Single Contact Field Mail Options Tab Screenshot

Remember: Contact settings override Menu Item's settings!

This is all due to the code logic in components/com_contact/controllers/contact.php:
if (!$params->get('custom_reply')) { //line 101
$sent = $this->_sendEmail($data, $contact);
If you want to change 'from' Email field look into your configuration.php's:
public $fromname = '';
Change the value of $fromname and you are done.

Any questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael