0

i m using windows, xampp, with appache sever.
plz tell me from the first how to send mail in php on localhost ...
this is really pizzing me ...
plz its very urgent plz help me
thank you...

3
Contributors
21
Replies
22
Views
8 Years
Discussion Span
Last Post by network18
0

mailing in php is very simple, php provide the mail() function that does everything for us -

to      = 'to@test.com';
$subject = 'subject';
$message = 'hello, how are you';
$headers = 'From: test@test.com' . "\r\n" .
    'Reply-To: test@test.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

The header part is optional, so you can exclude , if it bothers you.

0

What error do you get ? Did you install an smtp server, or did you change the httpd.conf to specify an smtp mail server ?

Edited by pritaeas: n/a

0

posting for others too, so that it can get faster.
here is your php -

<?
$to = "moonisha1@gmail.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "enquiry";

$fields = array();
$fields{"name"} = "name";
$fields{"add"} = "address";
$fields{"email"} = "email";
$fields{"ph"} = "phone";
$fields{"mobile"} = "mobile";
$fields{"city"} = "city";
$fields{"zip"} = "zip";
$fields{"country"} = "country";
$fields{"req"} = "req";

$body = "We have received the following information:\n\n";
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

if($from == '')
{
print "You have not entered an email, please go back and try again";
}
else
{
if($name == '')
{
print "You have not entered a name, please go back and try again";
}
else
{
$send = mail($to,$subject,$body,$headers);

if($send)
{
echo "<script type='text/javascript'> alert('Your mail has been sent');</script>";
}
else
{
print "We encountered an error sending your mail";
}
}
} 
?>
0

hey there's nothing wrong with your code. I got this below echo, means you mailed successfully =>

Array
(
    [req] => fsdf
    [name] => dfs
    [add] => dsfs
    [ph] => dsfs
    [mobile] => sdf
    [email] => dfds
    [city] => fdsf
    [zip] => dsfs
    [country] => dsf
    [submit] => submit
)

=>moonisha1@gmail.com
pritam is sending mail
We have received the following information: name: dfs address: dsfs email: dfds phone: dsfs mobile: sdf city: fdsf zip: dsfs country: dsf req: fsdf
From: dfds=>1

for this =>

<?
echo '<pre>';
print_r($_POST);
echo '</pre>';

$to = "moonisha1@gmail.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = " is sending mail";

$fields = array();
$fields{"name"} = "name";
$fields{"add"} = "address";
$fields{"email"} = "email";
$fields{"ph"} = "phone";
$fields{"mobile"} = "mobile";
$fields{"city"} = "city";
$fields{"zip"} = "zip";
$fields{"country"} = "country";
$fields{"req"} = "req";

$body = "We have received the following information:\n\n";
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

if($from == '')
{
print "You have not entered an email, please go back and try again";
}
else
{
if($name == '')
{
print "You have not entered a name, please go back and try again";
}
else
{
echo "=>".$to."<br>".$subject."<br>".$body."<br>".$headers;
echo "=>".$send = mail($to,$subject,$body,$headers);

if($send)
{
echo "<script type='text/javascript'> alert('Your mail has been sent');</script>";
}
else
{
print "We encountered an error sending your mail";
}
}
} 
?>

So just check with another email id,because in some organisation the mail to gmail is blocked for some reason or just check with your smtp server settings as above suggested or catch hold of your network admin. he might help in such case.

0

hey can u tell me wht settings u did.... did
u changed the ini settings

0

Nothing , just your code with some echoes at the right point to verify it.
You stil didnt get it?

0

actually it gives me
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\www\blackcatsecuritas\enquiry.php on line 50

so wht to do i tried everything but of no use

0

actually it gives me
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\www\blackcatsecuritas\enquiry.php on line 50

so wht to do i tried everything but of no use

0

You will need to edit your smtp settings in php.ini,
Like if you have configured an e-mail account for outlook and you've set your ISP's mail server for mail
delivery (something like smtp.something.net etc). Its the same in PHP.

You don't need to install and configure your own mail server to send mail

0

You will need to edit your smtp settings in php.ini,
Like if you have configured an e-mail account for outlook and you've set your ISP's mail server for mail
delivery (something like smtp.something.net etc). Its the same in PHP.

You don't need to install and configure your own mail server to send mail

0

Find php.ini here xampp for windows: C:\Program Files\xampp\apache\bin\php.ini
It seems that the smtp server is not installed on localhost, you need to provide the working smtp server to the php.
Change the below settings
SMTP = localhost
smtp_port = 25
to something like
SMTP = smtp.example.com
smtp_port = 25
In above case smtp.example.com you need to confirm it for you.

0

Find php.ini here xampp for windows: C:\Program Files\xampp\apache\bin\php.ini
It seems that the smtp server is not installed on localhost, you need to provide the working smtp server to the php.
Change the below settings
SMTP = localhost
smtp_port = 25
to something like
SMTP = smtp.example.com
smtp_port = 25
In above case smtp.example.com you need to confirm it for you.

0

try this -

<?
$to = "info@maharajarollingshuters.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "enquiry";

$fields = array();
$fields{"name"} = "name";
$fields{"add"} = "address";
$fields{"email"} = "email";
$fields{"ph"} = "phone";
$fields{"mobile"} = "mobile";
$fields{"city"} = "city";
$fields{"req"} = "req";

$body = "We have received the following information:\n\n";
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

if($from == '')
{
print "You have not entered an email, please go back and try again";
exit();
}
else
{
if($name == '')
{
	print "You have not entered a name, please go back and try again";
	exit();
}
else
{
/* echo "=>".$to."<br>".$subject."<br>".$body."<br>".$headers;
echo "=>".$send = mail($to,$subject,$body,$headers);*/
$send = mail($to,$subject,$body,$headers);
}
	if($send)
	{
		echo "<script type='text/javascript'> alert('Your mail has been sent');</script>";
	}
	else
	{
		print "We encountered an error sending your mail";
	}
}
?>
0

you have missed the outer check for the submit button's post , like -

If(isset($_POST['submit_btn_name']) && $_POST['submit_btn_name']!='')
{ 
//your code here
}

Put your entire code in this for loop

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.