Good day Experts ,this form displays error as shown below

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:\Tomcat 6.0\webapps\fphp\email-contact\send_contact.php on line 15
ERROR

the code is as follow

---------------------contact.php-------------------
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
// Contact subject
$subject ="$subject"; 
// Details
$message="$detail"; 

// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name <$mail_from>"; 

// Enter your email address
$to ='someone@somewhere.com'; 

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>

at my php.ini file I saw somthing like this

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

please how do i create the function mail so as to resolve this problem.Any help rendered is honoured.

Member Avatar for rajarajan2017

You written a proper code and nothing to worry about that warning message, because you are running your php file from your localhost (means from your local computer with/without network). So what you have to do is, Copy your files to the server, not your local machine.

I mean a hosting server, when you have a hosting server, they properly configured your mail server. In that situation your code will work without interruption. Bcoz the mail SMTP and PORT were already configured in your server.

You will not able to check from your local server, for that you have to configure your local system as a server (fack) by using some third party softwares.

Conclusion: Coding is correct and try your files from server. It will work.

Thank you for your kind response .Sir i have 2 question to ask you
1. if i publish my site with the code just like that it will work.
2. Assuming i want it to run in my local machine ,how do i go about with the 3rd party softwares .Is there any site where i can get it.
thanks

Member Avatar for rajarajan2017

Not exactly a third party, free tools also there. But you have to clearly configure for that by following their ReadMe fiiles. 6 Months back I tested it with a tool. Really I forgot the name. But you cant send any mails to gmail, rediff.com etc. you can send mail to you and you can test it whether received or not. Means, you will get the confirmation the code will work on the website.

thank you very much sir for your assistance. Please sir can you look at this code of my posting. Iam having a problem with my form and image upload to database.

Hi every one, i try to upload form data into database along with the image but the image name will be in my database as link while the image itself will be in a directory. I have use something like this code before it works i think but the problem with this code is what i dont know.Is it the directory as it keeps on returning the error
-------Sorry, there was a problem uploading your file------
the code is as follow

------------------------image.php--------------------------

<form enctype="multipart/form-data" action="addimage.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

---------------addimage.php-----------------------

<?php 
 
 //This is the directory where images will be saved 
 $target = "C:/Tomcat 6.0/webapps/fphp/image/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 
 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 
 
 // Connects to your Database 
 mysql_connect("localhost", "root", "root") or die(mysql_error()) ; 
 mysql_select_db("student") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>

the table is as follow

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo text);

now to view the image i developed something like this

<?php 
 // Connects to your Database 
 mysql_connect("localhost", "root", "root") or die(mysql_error()) ; 
 mysql_select_db("student") or die(mysql_error()) ; 
 
 //Retrieves data from MySQL 
 $data = mysql_query("SELECT * FROM employees") or die(mysql_error()); 
 //Puts it into an array 
 while($info = mysql_fetch_array( $data )) 
 { 
 
 //Outputs the image and other data
 Echo "<img src="C:/Tomcat 6.0/webapps/fphp/image/".$info['photo'] ."> <br>"; 
 Echo "<b>Name:</b> ".$info['name'] . "<br> "; 
 Echo "<b>Email:</b> ".$info['email'] . " <br>"; 
 Echo "<b>Phone:</b> ".$info['phone'] . " <hr>"; 
 }
 ?>

thanks and i will be glad to hear from you.

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.