Page 1 of 1

HOW to use mail() function;

Posted: Tue Feb 26, 2008 5:14 am
by pradip
i want to send an email using mail() function;

i m using follwing code;

$from = "ps_sach@yahoo.co.in";
$to = "pradip.p86@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body,"from: $email")) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}


but it is giving error like:

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 D:\Websites\quote.php on line 12

Re: HOW to use mail() function;

Posted: Tue Feb 26, 2008 11:08 am
by Christopher
Windows does not come with a SMTP server, you will need to install one.

Re: HOW to use mail() function;

Posted: Tue Feb 26, 2008 12:03 pm
by Mightywayne
Also, I highly suggest you go to

http://www.php.net/manual/en/ref.mail.php

and choose one of the custom-made functions in the bottom of the page, to avoid your mail getting picked up as spam.

Re: HOW to use mail() function;

Posted: Sun Mar 02, 2008 3:52 pm
by pradip
arborint wrote:Windows does not come with a SMTP server, you will need to install one.

I installed the SMTP server for windows...

i used following code...


$from = "pradip.p86@gmail.com";
$to = "p86_pradip@yahoo.com";
$subject = "hi";
$message = "just a test message! ";
@mail( $to, $subject, $message, "$from\r\nX-Priority: 1 (Highest)" )
or print "Could not send mail";

but it gives...Could not send mail..


please help me?

thanx in advance...

Re: HOW to use mail() function;

Posted: Mon Mar 03, 2008 8:04 am
by Sindarin
Try:

Code: Select all

//Send e-mail
 
//set variables
$from = "ps_sach@yahoo.co.in";
$to = "pradip.p86@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
 
//define headers
$headers = "MIME-Version: 1.0\r\n";
//set the below to your desired encoding
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: $to \r\n";
$headers .= "From: $from \r\n";
 
//send the e-mail
$result=mail( $to, $subject, $body, $headers);
if ($result=1)
{
echo "<font color='green'>test mail was sent from $from to $to</font>";
}
else
{
echo "<font color='red'>test mail was NOT sent</font>";
}

Re: HOW to use mail() function;

Posted: Sun Mar 16, 2008 2:53 am
by pradip
I tried all the way but it didn't work.

i m using wamp server..
is there any requirement to install smtp server on windows?

please help me in detail .

thanx in advance...