Sending e-mail from localhost in PHP for Windows Environment.

Posted: July 29, 2010 in Stay Hungry Stay Foolish..
Tags: , , , , ,

I know how it feels when you have to migrate to test server for every single change in mail,sometimes, we have to even wait

for our seniors to make the upload so that we can proceed, this is all because our “Major-General Localhost strictly follows

his own rules like e-mail is not going from the localhost while using XAMPP or WAMP or any other PHP servers in windows

environment” :-), but somebody has really very well said that “Rules are made to be broken..”  Well, I can help you in this

situation. In this article,  I am going to tell you how to send e-mail from localhost in PHP.

  1. Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
  2. Search for the attribute called “SMTP” in the php.ini file.Generally you can find the line “SMTP=localhost“. change the localhost to the smtp server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25. I’ve set the following values in my php.ini file. “SMTP =
    smtp_port = 25
  3. Restart the apache server so that PHP modules and attributes will be reloaded.
  4. Now try to send the mail using the mail() function , mail(“”,”Subject:How to break rules of localhost..”,”Body:I have an idea to break the rule.”); you might get the warning like this, Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
  5. Now specify the following headers and try to send the mail again,

$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From:’ . “\r\n”;
mail(“”,”Subject:How to break rules of localhost..”,”Body:I have an idea to break the rule.”,$headers);

Well that’s all, the mail is sent to “”.

Note : Some smtp server verifies the email address of the sender so the email address which is in the place of  “” ( should be a valid and existing email address otherwise mail might not be sent to the “”.

Please give your feedback….

  1. Tejaswi Sharma says:

    Hey Pranav,
    This is only applicable to users who are using windows for their development environment. Those who are using any linux variant for the development. They have to use sendmail or postfix to relay your mails to your destination smtp server.

    My personal favourite is postfix and 100% conpatible for users who were earlier using sendmail. Its easy to install and very easy to configure.

    • Pranav Dave says:

      @Tejaswi, yes it is only for Windows users….Postfix is certainly the best among it, but I thought of the way a starter accessing the wamp and trapped in localhost mail thing.. hence this solution for Windows Environment.. On basis of your comment I am appending “for Windows Environment” in the title…

      Thanx Again.. Keep Spreading The Knowledge..
      Happy Coding……

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s