Thursday, January 28

How to send mail from Localhost with XAMPP and mercury/32

Had tried to make php mail() work on localhost. But had failed. So gave up. This was around 8 months back. Now again some days back had to use the Php mail function on one project. This time I had the liberty to test my code on an external web server, but i tried again to make it work on my localhost.

A lot of google searching and some simple steps, I could make it work.So here sharing my experience with you. Hope this helps someone like me.

I use XAMPP as my local web server on my Windows machine. For php mail() function to work on the localhost, you need a SMTP mail server.

Requirements

A Web server : Here we use the xampp package. You can download it from here. It is very easy to install and does not require any expertise.
A Mail server : Mercury/32 Mail Transport System is an excellent mail server bundled with XAMPP. So no need to search for any other mail server.
A Mail Client : You need to have a mail client to receive mails sent from localhost or basically from your Mercury/32 mail server. Mail clients include outlook express, thunderbird, Eudoramail etc. For this tutorial I will be using the default mail client available with Windows system , ie the outlook express.

The Steps to Configure Mercury/32 mail server


The following steps will guide you through the working of mail function on localhost.
1)      You need to start the localhost web server. The XAMPP in this case.




2) By default XAMPP will not start the mercury mail server. So you need to click on start to start the mercury/32 on the XAMPP control panel.



3)      Click on the Admin Button next to mercury on XAMPP control panel. This will open the Mercury/32 Admin Panel. Click on Configuration -> Manage Local users.


                       

4)      Create a New User. Let
Username : root
Password : root


           
      5) Next, from the Mercury/32 Admin panel, Go to Configurations -> Mercury SMTP server and   make the following Changes.
            IP Interface to use : 127.0.0.1
            Listen to TCP/IP port : 25
            Announce Myself as : 127.0.0.1



      6)Next, from the Mercury/32 Admin Panel , Go to Configurations -> Mercury POP 3 Server and fill in the following details.
            Listen to TCP port : 110
            IP Interface to use : 127.0.0.1




       7) Next, from the Mercury/32 Admin Panel, Go to Configurations - > MercuryE SMTP client Configuration , and make the following changes
            Identify Myself as : 127.0.0.1
            Name server : 127.0.0.1



       8) Next step is from the Mercury/32 panel go to Configuration -> Mercury D pop3 client and there create a new Account. Click on “ADD” and then enter the following details for “Edit POP3 mailbox definition” dialog box.
            POP3 Host : 127.0.0.1
            Username : root
            Password  : root
           And then click on save.




This finishes Configuration of your Mercury/32 Mail transport system.

We now have to configure a mail client, so as to receive mails. We will use the windows default mail client, the outlook express. The following steps will guide you to create a user account on outlook express.

Steps to set up OUTLOOK EXPRESS




     1)Open Outlook express and then click on Tools -> Accounts -> Add, and then click on Mail




     2)For new Internet account on outlook express , create a new user
            Enter display name: root



            Enter email Id: root@localhost.com



            Then click Next. On the Internet Connection wizard,
            Select POP3 for my incoming mail server.
            For Incoming mail (POP3, IMAP, HTTP) server, enter
            127.0.0.1
            For Outgoing (SMTP) server, enter
            127.0.0.1



            Click on Next and then , enter the following fields
            Account name : root
            Password : root
            Click on finish and you are ready to Go.

Once you have finished creating a account on Outlook express , send a test mail to yourself.




You can now test your php code to check if your script is working successfully or not.You can try this script. Copy the code and save it in a file for eg mail.php. Save this file in your root folder , for xampp it will be in your htdocs folder.

//php code to send mail,
//author : idrish laxmidhar
//Use this code to send a test mail from your localhost.

$to = "root@localhost.com";
$subject = "Hi!";
$body="test".PHP_EOL;
$body.="Hello World. If all went well then you can see this mail in your Inbox".PHP_EOL;
$body.="Regards".PHP_EOL;
$body.="Idrish Laxmidhar".PHP_EOL;
$body.="http://i-tech-life.blogspot.com".PHP_EOL;

$headers = "From: root@localhost.com";

if (mail($to, $subject, $body, $headers)) {
  echo("Message successfully sent!
");

 } else {
  echo("Message delivery failed...
");

 }
?>



 Run the script. If all went well, the script should execute successfully. Check your email. You should receive an e-mail.




Well this finishes the tutorial. Hope it helps someone out there. 
P.S This is my first attempt to write a tutorial. your queries or Suggestions are highly appreciated. Thanks

Monday, January 18

JQuery - Lesson Learned

Jquery is full of awesomeness. Love this javascript library which makes working with web applications so much easy. Have been working on with it past so many months. And the best thing about jquery is there are already developed jquery plugins. Yes , they are free and very useful.

Some time back i had to work on web page which had a verfiy and delete option for the admin. Upon clicking on verify/Delete i wanted to pop up an alert confirmation box. Could have used javascript but then came across  a jQuery alert plugin. The best part about this plugin is you can style your alert box. So i decided to use this plugin. Very easy to integrate , i had done exactly as mentioned in the tutorials plus also checked out 9lessons tutorials.

All set , i tested out the code , but to my disappointment , it did not work. I checked the code and re-checked it for any syntax errors but all in vain. Tried googleing out the issue and also posted the issue on stackoverflow here. This cost me more then 3 hrs.  

Soon after when i was about to give up, I landed on the documentation of the alert plugin and a small line got my attention. It said , the plugin requires jquery to be of version 1.2.6 or above. Immediately i checked my jquery version , and to my surprise i was using jquery version 1.2.2. Yeah quite an older one, but soon got myself the latest version of jquery.

Lesson learned :
1) Never Give up.
2) Read documentations properly.


Saturday, January 9

Fwd Joke.

Got this damn funny awesome joke as a fwd on my mail. Could not resist putting it up on my blog. Thanks to samidha for forwarding it. Here it goes

Aaj Tak gets news that 100 sardars are killed in a train accident at
Amritsar station. Only one sardar left alive.

The correspondent goes to him and asks, "Sardarji how did it happen?"

Sardar: "Oh ji pucho mat. sab kuch sahi tha sab log platform par khade
gaadi ki wait kar rahe they. Achanak announcement hui ki shatabdee
express 2 no. platform par aa rahi hai. Jaise hi sab ne suna ki gaddi
PLATFORM PAR aa rahi hai, sab log apni jaan bachane ke liye patri par
kood gaye. Aur tabhi gaddi patri par aa gayi."

Aaj tak: "Thank god. Aap ne samajhdari dikhayee. Aap patri par nahin
koode."

Sardar: "oe nahin ji main to suicide karne ke liye patri par hi leta
tha. Jaise hi announcement hui main to platform par chad gaya ."

Enjoy your day..

Friday, January 1

happy new year

It was a splendid and awesome year 2k9 for me. Lots of downs and downs..Did nothing productive, no money and so the wish list i had made for 2k9 is still unfulfilled. Iphone is still a dream , but i am ready to compromise and settle down with some kool multimedia, smartphone or any cheaper pocketPc. Also owning a high end PC seems a day dream. Am still stuck with an intel celeron 1.1Ghz, 128MB Ram. Oh and by the way got myself a 160 GB hard disk which sums up my storage space to 200GB. With Doordarshan all day on TV, i am quite happy i can atleast watch movies on my PC or watch some video tuts.

Apart from gadgets, learned some great things, photoshop, dreamweaver, ajax and jquery. Designed some great websites well actually 2 of them which still ain't approved from whom they were designed for. Made a lot of F.R.I.E.N.D.S , watched movies, ate lots of chicken and kheema, used friends laptop, (actually typing this post from friends laptop), traveled alone to mumbai (my biggest achievement). So many things happened in 2k9 , dnt remember them now or may be they aren't worth remembering.

What up with 2k10
Earn money, get interesting work. Travel, eat in MacD and Kfc once every month, play latest PC games, buy Xbox 360 / PS 3 (whichever is cheaper), make some friends , make some more friends, Need for Speed - Shif , read books, buy some books, and the list grows as the day passes by.

Wish you a happy new year 2k10 !!!