Click here to Skip to main content
15,036,363 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I try to use mail() function in php to sent to someone but it always show 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:\wamp\www\PHP\Email\sent_mail.php on line 7
We encountered an error sending your mail"

------------
my code:

$to = "abc@gmail.com";
$subject = "Test";
$email = "dsb@gmail.com"
$message = "Hello"
$headers = "From:$email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully" }
else
{print "We encountered an error sending your mail" }
Posted

1 solution

The error message says it all:
Chetrabbu wrote:
verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

You need to tell your PHP environment how to contact an SMTP server. There obviously isn't a local one running, so you need to either set one up or use your ISP's one. To use the ISP's one, specify something like
SMTP = mail.ipsname.com
smtp_port = 25

in your php.ini. You could use ini_set() inline in your PHP, but that really only makes sense if you want to change things on the fly.
   
v2
Comments
Chetrabbu 11-Jun-10 5:39am
   
Than you sir Peter now i am understand .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900