Sending mail via Mercury on localhost using codeigniter and XAMPP

2009 Jan 25
 
mercury-logo.jpgThis is my first time to use Mercury on XAMPP, I never had a mail project before so I guess I'm gonna blog it for future reference. Obviously, we will be using SMTP to send mails and POP3 to receive them. Since we do not have sendmail installed in Windows XP.

Using Mercury bundled witn XAMPP is so straight forward. I am assuming you have already installed XAMPP and Mercury Mail Transport is already running. I also assume you already know how to setup a mail client (eg Outlook, Outlook Express, ThunderBird, EudoraMail are few of them). Setting up a mail client is not covered here. 




Requirements:
  • XAMPP - Our webserver
  • Codeigniter - PHP Framework
  • Mail Client - Receive mails
  • Text Editor - TextMate is a very good editor but I use notepad

xampp-control-panel.jpg
Now, all we need to do is Add Users for testing: 
1. Open XAMPP Control Panel and Click on Start on the Mercury Section
2. Click on the Admin Button to Add Users
3. On the Mercury Menu, go to Configuration -> Manage Local Users
4. To Add an account Click on ADD 
5. Add your desired test Accounts by filling in the Username, Name and Password field
6. Then click OK, then click Close


Before testing, you might want to configure codeigniter's config to store your sender accounts. To do that: 
1. Navigate to your codeigniter application->config folder 
2. You may create you own config file or add them in the email.php config
3. if email.php does not exist you may create one. 
4. You can use the basic config for sending smtp/pop3 below:


5. You may add your test account so you don't have to manually type them whenever you send.Take note, I used localhost.com as my host name. Mail clients may not permit you to add an account with just localhost so adding .com, .net, .org will do the trick.


6. Remember not to close your
7. If you want to, you can also configure codeigniter to autoload the email config by adding it at the autoload.php file

We can now start sending mail with code igniter:
1. At the application->controllers create a controller class: 
config->item('email_address', 'email');
$from_name = $this->config->item('email_name', 'email');
$to = ''; 
$to_name = "To Name";
// we load the email library and send a mail
$this->load->library('email');
$this->email->from($from, $from_name);
$this->email->to($to, $to_name);
$this->email->subject('Email subject');
$this->email->message('Testing the email class.');
$this->email->send();
//to debug we can use print_debugger()
echo $this->email->print_debugger();
}
}
2. On your browser, type in http://localhost/codeigniter/test_mail
3. Check you mail client for new mails. 
4. Thats it! We have successfully sent a mail using Mercury on XAMPP on in your local computer.

test-mail-success.jpg

Please the codeigniter manual for more resource about its email class. 


Related Entries

Leave a comment

Recent Entries

  • Unable to edit entry body in movable type

    Warning: Error in parsing value for property 'display'. Declaration dropped.Warning: Error in parsing value for property 'white-space'. Declaration dropped.Warning: Unknown property 'filter'. Declaration dropped.Warning: Unknown...

  • Old School Favorite: Pacman

    Pacman is one of my personal favorite arcade game. Even today, I can still imagine myself playing some old school games, and i must admit...

  • Earning from your blog with Amazon Associates

    Blogging can be fun, but earning and at the same time having fun is way much better. Here's how to make the most of your...

  • Sending mail via Mercury on localhost using codeigniter and XAMPP

    This is my first time to use Mercury on XAMPP, I never had a mail project before so I guess I'm gonna blog it for...

  • Submitting Sitemaps to Search Engines Google, Yahoo and MSN

    Sitemaps are xml documents used by the search engines to index your website. it is not very crucial for your website but it will help...