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 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
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.
Please the codeigniter manual for more resource about its email class.
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]