0

I am trying to send mail using php.And i am using WampServer. so i tried the following code

ini_set("SMTP","smtp.gmail.com" );
ini_set("smtp_port","465");
ini_set('sendmail_from', 'person1@gmail.com');          
$to = "person2@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "person1@gmail.com";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
   if( $retval == true )  
   {
      echo "Message sent successfully...";
   }
   else
   {
      echo "Message could not be sent...";
   }

but it take more time to connect and says could not connect with localhost. Please help me in solving the problem

krishna
  • 3,996
  • 2
  • 27
  • 56

3 Answers3

2

try this configuration:

http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/

this might help.

Mark
  • 7,818
  • 14
  • 46
  • 78
-1

somehow, instead of "smtp.gmail.com", for me it works with "ssl:smtp.gmail.com" This line:

ini_set("SMTP","smtp.gmail.com" );

should be

ini_set("SMTP","ssl:smtp.gmail.com" );

Also, see this response to a similar question: Send email using the GMail SMTP server from a PHP page

Community
  • 1
  • 1
naivists
  • 31,708
  • 5
  • 57
  • 81
  • it is giving following error Warning: mail(): Failed to connect to mailserver at "ssl:smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() – krishna Feb 08 '13 at 10:11
-1

You're trying to send mail from your localhost (Your PC) I guess It's not setup to send mail. Move the script to a production server and it will work

Rakesh K
  • 670
  • 3
  • 13
  • 26