A
Anonymous
Guest
<?php
if ($Submit<>"")
{
if ($email == "" ) {
$mailfm = "E-mail cannot be empty ";
$msg = "Message";
}
if ($mailmessage == "") {
$cndet = "Message cannot be empty";
$msg = "Message";
}
if ($file != "") {
$errors= "";
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp =$_FILES['file']['tmp_name'];
$file_ext = substr($file_name, strripos($filename, '.'));
$file_basename = substr($filename, 0, strripos($filename, '.'));
if ($file_size > 5242880){
$afl = "File size must be less than 5 MB";
$msg = "Message";
}
if (empty($errors)==true) {
$cn = md5(uniqid(rand()));
$newname = $cn . $file_basename . $file_ext;
move_uploaded_file($file_tmp,"uploads/".$newname);
} else {
}
}
if ($msg == "") {
$result = "Name : $nme\n\n";
$result .= "E-mail id : $email\n\n";
$result .= "Subject : $mailsubject\n\n";
$result .= "Message : $mailmessage\n\n";
$result .= "File saved path : /uploads/$newname\n";
$to = "yourname@yourcompany.com";
$subject = "Online form";
$mailheaders = "";
mail($to, $subject, $result, $mailheaders);
$message = "Your message has been sent successfully";
}
}
?>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>cform</title>
<style type='text/css'>
body {
background: #7eb9e0;
}
fieldset {
padding: 50px;
width: 180px;
height: 590px;
background-color: #2e4e63;
}
form {
display: table;
padding-left: 330px;
padding-top: 3px;
width: 180px;
height: 250px;
}
form .cform{
display: table-row;
}
form .cform label {
display: table-cell;
padding: 10px;
width: 200px;
}
textarea {
vertical-align: top;
resize: none;
}
.cform {
font-family: verdana;
color : #e3e05c;
font-size: 15px;
}
#cntfrm {
width: 380px;
height: 30px;
margin: 15px;
border: 1px solid #ffffff;
border-radius: 6px;
}
#msg {
margin: 15px;
border: 1px;
}
.message {
color : #e3e05c;
padding-left: 83px;
text-align: center;
}
.mailfm {
color : #e3e05c;
text-align: center;
}
.cndet {
color : #e3e05c;
text-align: center;
}
.afl {
font-size: 18px;
color : #e3e05c;
text-align: center;
}
#file {
margin-left: 15px;
}
.submit {
margin-left: 230px;
margin-top: 30px;
}
#send {
width: 110px;
height: 35px;
</style>
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data" >
<fieldset>
<p><font size="5" color = "#e3e05c" >You can use the form below to contact</font></p>
<div class="message">
<?php echo "$message";
echo "$mailfm";
echo "$cndet";
?>
</div>
<div id="cfm" class="cform">
<label>Name</label>
<input id="cntfrm" name="nme" size="35" type="text">
</div>
<div class="cform">
<label>E-mail id</label>
<input id="cntfrm" name="email" size="35" type="text">
</div>
<div class="cform">
<label>Subject</label>
<input id="cntfrm" name="mailsubject" size="35" type="text">
</div>
<div class="cform">
<label>Message</label>
<textarea id="msg" name="mailmessage" cols="45" rows="10"></textarea>
</div>
<div class="cform">
<label>Attachment</label>
<input id="file" type="file" name="file" value="" />
<p><font size="2" color = "#e3e05c" >Upload file less than 5MB</font></p>
</div>
<div class="afl">
<?php
echo "$afl";
?>
</div>
<div class="submit">
<input name="Submit" id="send" value="Submit" type="submit" >
</div>
</fieldset>
</form>
</body>
</html>
In the above code, replace $to="yourname@yourcompany.com" with your id where you want to receive the email.
Find the code $result .= "File saved path : /uploads/$newname\n"; Here is the 'uploads' directory where your uploaded file will be stored. Check whether 'uploads' directory exists or not otherwise replace the 'uploads' directory with othere name.
if ($Submit<>"")
{
if ($email == "" ) {
$mailfm = "E-mail cannot be empty ";
$msg = "Message";
}
if ($mailmessage == "") {
$cndet = "Message cannot be empty";
$msg = "Message";
}
if ($file != "") {
$errors= "";
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp =$_FILES['file']['tmp_name'];
$file_ext = substr($file_name, strripos($filename, '.'));
$file_basename = substr($filename, 0, strripos($filename, '.'));
if ($file_size > 5242880){
$afl = "File size must be less than 5 MB";
$msg = "Message";
}
if (empty($errors)==true) {
$cn = md5(uniqid(rand()));
$newname = $cn . $file_basename . $file_ext;
move_uploaded_file($file_tmp,"uploads/".$newname);
} else {
}
}
if ($msg == "") {
$result = "Name : $nme\n\n";
$result .= "E-mail id : $email\n\n";
$result .= "Subject : $mailsubject\n\n";
$result .= "Message : $mailmessage\n\n";
$result .= "File saved path : /uploads/$newname\n";
$to = "yourname@yourcompany.com";
$subject = "Online form";
$mailheaders = "";
mail($to, $subject, $result, $mailheaders);
$message = "Your message has been sent successfully";
}
}
?>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>cform</title>
<style type='text/css'>
body {
background: #7eb9e0;
}
fieldset {
padding: 50px;
width: 180px;
height: 590px;
background-color: #2e4e63;
}
form {
display: table;
padding-left: 330px;
padding-top: 3px;
width: 180px;
height: 250px;
}
form .cform{
display: table-row;
}
form .cform label {
display: table-cell;
padding: 10px;
width: 200px;
}
textarea {
vertical-align: top;
resize: none;
}
.cform {
font-family: verdana;
color : #e3e05c;
font-size: 15px;
}
#cntfrm {
width: 380px;
height: 30px;
margin: 15px;
border: 1px solid #ffffff;
border-radius: 6px;
}
#msg {
margin: 15px;
border: 1px;
}
.message {
color : #e3e05c;
padding-left: 83px;
text-align: center;
}
.mailfm {
color : #e3e05c;
text-align: center;
}
.cndet {
color : #e3e05c;
text-align: center;
}
.afl {
font-size: 18px;
color : #e3e05c;
text-align: center;
}
#file {
margin-left: 15px;
}
.submit {
margin-left: 230px;
margin-top: 30px;
}
#send {
width: 110px;
height: 35px;
</style>
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data" >
<fieldset>
<p><font size="5" color = "#e3e05c" >You can use the form below to contact</font></p>
<div class="message">
<?php echo "$message";
echo "$mailfm";
echo "$cndet";
?>
</div>
<div id="cfm" class="cform">
<label>Name</label>
<input id="cntfrm" name="nme" size="35" type="text">
</div>
<div class="cform">
<label>E-mail id</label>
<input id="cntfrm" name="email" size="35" type="text">
</div>
<div class="cform">
<label>Subject</label>
<input id="cntfrm" name="mailsubject" size="35" type="text">
</div>
<div class="cform">
<label>Message</label>
<textarea id="msg" name="mailmessage" cols="45" rows="10"></textarea>
</div>
<div class="cform">
<label>Attachment</label>
<input id="file" type="file" name="file" value="" />
<p><font size="2" color = "#e3e05c" >Upload file less than 5MB</font></p>
</div>
<div class="afl">
<?php
echo "$afl";
?>
</div>
<div class="submit">
<input name="Submit" id="send" value="Submit" type="submit" >
</div>
</fieldset>
</form>
</body>
</html>
In the above code, replace $to="yourname@yourcompany.com" with your id where you want to receive the email.
Find the code $result .= "File saved path : /uploads/$newname\n"; Here is the 'uploads' directory where your uploaded file will be stored. Check whether 'uploads' directory exists or not otherwise replace the 'uploads' directory with othere name.