HOW to use mail() function;

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pradip
Forum Newbie
Posts: 5
Joined: Wed Feb 20, 2008 11:42 pm

HOW to use mail() function;

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HOW to use mail() function;

Post by Christopher »

Windows does not come with a SMTP server, you will need to install one.
(#10850)
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Re: HOW to use mail() function;

Post 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.
pradip
Forum Newbie
Posts: 5
Joined: Wed Feb 20, 2008 11:42 pm

Re: HOW to use mail() function;

Post 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...
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: HOW to use mail() function;

Post 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>";
}
pradip
Forum Newbie
Posts: 5
Joined: Wed Feb 20, 2008 11:42 pm

Re: HOW to use mail() function;

Post 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...
Post Reply