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. 


Tweet this post

Related Entries

44 Comments

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Ruth

[link deleted]

Thanks to share this. Really help mine.

lll

Really useful ideas...Thanks for the great post...

This is an excellent post. I use normal mail service for which I just have to setup my client, but I think this is important if you're in any organization and setting up your local mailserver. It'll simply reduce costs and save time because those emails would allow only within organization communication and not outside.

When talking to web developers it seems that the overwhelming majority are Mac users. That certainly seems to be the case in the ExpressionEngine community, but there are still a large number of developers using Windows XP, Vista or soon Windows 7.

Have you ever been frustrating, why e-mail is not going from the localhost while using XAMPP or WAMP or any other PHP servers in windows environment? well in that situation i think i can help you.In this article i am going to tell you how to send e-mail from localhost in PHP.

tried hamster too, nothing works, the print debugger looks fine though, I don’t see what’s going wrong.

Ooooh that fixed a problem I've been having. Thank you!!

Thanks for the code instructions, i normally use formmail etc, it's simple to configure. I will try your code later today.

hi.. thanks for the share. I'll try it..hope it work

I never used this before and it looks complicated :)
I'll stick to my outlook.

very interesting, thank you for sharing. can you please update us on progress and if you are still using it? thanks again.

Thanks for this post, budddy! I was long freaked out how to send email through my localhost server… now my prob’s solved.

I agree with most of what has been said. Some good points made.

Lenovo Computers

I really liked this post. Can I copy it to my site? Thank you in advance.


Thank you for a good post. I will save this page so I can review the information again.

What is the advantage of using Mercury bundled with XAMPP? Why would I want that? What are its bad points?

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.

I am sorry but I am a newbie on this. Aren't you going to discuss how to set up mail client in your future posts?

I used Mercury on XAMPP and I think it is one of the best.

tried the potato battery myself, but the the print debugger just does the job.

http://www.killyourbellyfat.com

Thanks for the share that would be a good way, going to try it out

very interesting, thank you for sharing. can you please update us on progress and if you are still using it?

I just gave this shot. It was easy to install, and seems to work just fine. Thanks for the tip!

Thank you for the tutorial. This is quite very helpful. But can you provide more entries on this? Thanks

Thanks for the tips and tutorials. I am looking forward to reading other posts on this topic.

Great post. I am looking forward to more informative posts from you.

Okay fine. You've convinced me. I'll start using XAMPP -- it just seems so straightforward.

I agree with you XAMPP is good.

Thanks for code and directions.

This one is another way to send mail. Before I have no idea about Sending mail via Mercury, but after I read your post, I understand it better.

Thanks; you cleared up a few questions I had on this subject. Merci beaucoup.

I was trying to figure out this very thing but couldn't do it on my own; I found you by searching in goog. Thanks for the info.

Nice Post....
Thank You

Nice post, just in time for my next project. Thanks.

Thank you for this great article, helped me out a lot!

Great post. I agree with you XAMPP is good.

It'll simply reduce costs and save time because those emails would allow only within organization communication and not outside.

I didn't receive the email in my outlook inbox and i didn't receive error message.. Why?

How can i configure my outlook and Xampp 4 testing purposes?

Intimately, the post is actually the best on this laudable topic. I harmonize with your conclusions and will eagerly look forward to your future updates. Saying thanks will not just be adequate, for the fantastic lucidity in your writing.

Its a great post. I read it fully and I must say very very interesting.

Leave a comment


About Me


Alfredo Sanchez is an internet professional focusing on the study search engines behavior in particular. Supports Free Open Source Software and currently develops applications with it using XAMPP.

Recent Entries