hi this is a form.php

<html><body><font face=Arial size=2> 
<form method="post" action="contact.php"> 
<table bgcolor=#ffffcc align=center> 
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr> 
<tr><td>Department:</td><td><select name="sendto"> <option value="info@mycompany.com">General</option> <option value="support@mycompany.com">Support</option> <option value="sales@mycompany.com">Sales</option> </select></td></tr> 
<tr><td><font color=red>*</font> Name:</td><td><input size=25 name="Name"></td></tr> 
<tr><td><font color=red>*</font> Email:</td><td><input size=25 name="Email"></td></tr> 
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr> 
<tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> 
<tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr> 
<tr><td colspan=2>Message:</td></tr> 
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> 
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> 
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr> 

and this is a contact.php

$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from"; 
$subject = "Web Contact Data"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"list"} = "Mailing List"; 
$fields{"Message"} = "Message"; 

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

$headers2 = "From: noreply@YourCompany.com"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";

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); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
{header( "Location: http://www.YourDomain.com/thankyou.html" );} 
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } 

it gives following error message

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\contact.php on line 34

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\contact.php on line 35

please help me

Recommended Answers

All 3 Replies

i used mail function that time it's worked perfectly
but i used this from directly server.
so i think you use this from local pc so may be you need to do some setting in php.ini file ya smtp port
this solution you should get from the google search ok


Is this on the local server or a remote host?

If this is on a webserver then your host should set this up for you.

Else if it is on local host it is not worth setting up. Just suppress it with and @ infront of the mail function.

When you upload to a webserver it will work properly.

If you really want to set it up so you send mail then you need to look into getting a mail server then getting and configuring a DNS server, then add these settings to your php.ini.

You could always just register a GMail account and use the example I posted in this post.

Note, that example uses PHPMailer. (Which I highly recommend whenever you need to sen emails.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.