Oct
1

How to configure mail from localhost ( wamp ) using PHP?

Author Arpi    Category PHP, Tips     Tags ,

I have searched a lot when I was required to configure mail using my localhost for my project. At many sites I have read that it’s just not possible to send mail using localhost. You have to upload your project on the net.

But after searching a lot I get to know that it’s possible to send mail using localhost without uploading the project.  And today I post this blog so that the PHP programmer can get to know that it’s not that we just cannot send mail from localhost .We can do.

Steps to send mail from localhost:

  • From your wamp open php.ini file.
  • Search for mail function in that file and replace its content as follow.

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = your serve’s host name. (ex.  mail.test.com)

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

sendmail_from = Sender email Id .(ex. [email protected]

  •   Save the php.ini file.
  • Write code to send mail.

 <?php
$to  = ’[email protected]’;

// subject
$subject = This is the Test mail’;

// message
$message = ’
<html>
<head>
<title>Test message</title>
</head>
<body>
<p> Hey its working!.. ..</p>
</body>
</html>
‘;

// To send HTML mail, the Content-type header must be set
$headers  = ’MIME-Version: 1.0′ . ”\r\n”;
$headers .= ’Content-type: text/html; charset=iso-8859-1′ . ”\r\n”;

// Additional headers
$headers .= ’To: Receiver name <[email protected] >’ . ”\r\n”;
$headers .= ’From: Sender name <[email protected]>’ . ”\r\n”;

// Mail it
mail($to, $subject, $message, $headers);
?>

You are done with the steps. Now run your wamp and continue your project further.

 

 

Arpi

hiii friends… i am doing msc in computer application and information technology. we are here to share our knowledge and idea on shareprogrammingtips.com.

More PostsWebsite

You may like to read this also....

12 Comments to “How to configure mail from localhost ( wamp ) using PHP?”

  • webdesignergeeks October 1, 2011 at 12:58 pm

    Nice article Arpi
    Keep it up :) !!!

  • ljc kredyt October 9, 2011 at 2:19 am

    Hello all. I agree with you – 100% +. Thank you for the information. Bruce.

  • Hardik October 15, 2011 at 6:08 am

    Good One!!!!!

  • ugg boots for men sale October 24, 2011 at 7:35 am

    This is excellent! How do you uncover these items?

  • Vernon Mattina December 31, 2011 at 1:31 am

    Keep working ,splendid job!

  • Anil February 22, 2013 at 8:04 am

    Hi,

    Not working for me. I am using gmail smtp for sending mails.
    any body help me for this

    Thanks!

  • SUGANYA March 3, 2013 at 10:33 am

    I AM NEW TO PHP. I CREATED WEBSITE LOCALY. I CREATED ONLINE TEST. I WANT TO SEND SCORE TO USER WHO ATTEND THE EXAM. HOW SHOULD I DO.

  • sureshranju March 31, 2013 at 3:43 pm

    Arpi nice work tutorial its mine check out
    sureshranju recently posted..drop down menu does not display my information from my mysql databaseMy Profile

  • Ankur April 19, 2013 at 3:23 pm

    Hello there, it really a very simple and nice way to send email but when I tried it i am getting the following error

    ning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. t16sm13728702pbs.32 – gsmtp in C:\wamp\www\tp\forgot.php on line 27

    Any help??

  • shinto peter May 21, 2013 at 2:10 pm

    can u please help me
    i have tried above setting but iam getting following error message

    Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\mail\index2.php on line 29

  • Vruddhi October 3, 2011 at 11:48 am

    Useful information Arpi. Thanks!!

Post comment

*

CommentLuv badge
Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

latest comments

Find us on Facebook

Top Authors

35 posts
saurabh
22 posts
10 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link