0
  <?php
   $to = "someone@example.com";
   $subject = "Test mail";
   $message = "Hello! This is a simple email message.";
   $from = "someonelse@example.com";
   $headers = "From:" . $from;
   mail($to,$subject,$message,$headers);
   echo "Mail Sent.";
 ?>

When I run these script I get these error

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:\xampp\htdocs\website\mail.php on line 7 

What I have to do now? Could anyone tell me the way to do it ? Okay I have found that file but what are the fields I need to update could you suggest me some code so that i paste it these and save?

niko
  • 9,285
  • 27
  • 84
  • 131
  • Is there an SMTP service running on localhost? The PHP code is successfully trying to connect to one, but there doesn't seem to be one running. – David Sep 11 '11 at 20:35
  • It means php is configured to connect to the mail server on the local machine, which apparently isn't running. You lied to php and now you're being punished :P – Chris Eberle Sep 11 '11 at 20:36
  • so what I have to do ? could you tell me the solution please! – niko Sep 11 '11 at 20:38
  • I really need it what I have to do! My project needs these please help me! – niko Sep 11 '11 at 20:38
  • if you don't run your own mail server, you need to find one you can use from 'localhost' either your isp, or Gmail. If you plan to host this script somewhere the mail server will probably be taken care of for you. –  Sep 11 '11 at 20:46

3 Answers3

2

You have to configure your php.ini with a valid smtp server and email address.

Cydonia7
  • 3,744
  • 2
  • 23
  • 32
1

You need to configure PHP to use a working SMTP service in order to send SMTP email. Here's an article that discusses the subject.

Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.

David
  • 208,112
  • 36
  • 198
  • 279
1

I guess that this question is the same as your other question...

If so, I guess you are trying to send an email through GMail's SMTP server. Their server requires authentication, which PHP's mail function doesn't support. As I answered you in the other question, you can use Zend_Mail to do this. You can also use PEAR Mail like in the example in the other question. Either way you will need to download some external file, include it in your code and use it.

Community
  • 1
  • 1
Ofir
  • 415
  • 2
  • 7