I wanting help with a php contact form with attachment;. Seem to be working ok be I do have a couple of errors which I like to for fresh set of eyes to loo for me.
<?php
if($_POST["submit"]){
// Empty out errors array
unset($errors);
$errors = array();
// Validate fields
if (empty($_POST['name'])){
//Validate user Last Name
$errors[] = "You have not entered in your last name.";
} else{
$names =$_POST['name'];
}
// Validate sending email
if (empty($_POST['email'])){
$errors[] = "please enter a validate eMail Address.";
}else if(strlen($_POST['email']) > 350){
$errors[] = "Your eMail maybe to long. Please review and correct.";
}else if (filter_var($_POST['email'] , FILTER_VALIDATE_EMAIL) === false){
$errors[] = "Please provide your right email address.";
}else {
$email = $_POST['email'];
}
if (empty($_POST['looking'])){
//Validate user Last Name
$errors[] = "You have not entered in your last name.";
} else{
$comments =$_POST['looking'];
}
}
if (count($errors)==0) {
echo "Your form entries have errors:<br />";
foreach($errors as $key => $error) {
echo $error . "<br />";
}
} else {
$myemail = 'root@localhost';
$to = $myemail;
$subject = "Your Lady of interest name: $names ";
$names =$_POST['name'];
$email = $_POST['email'];
$comments =$_POST['looking'];
$message = "$names $email $comments";
$att = $_FILES['att'];
$att_path = $_FILES['att']['tmp_name'];
$att_name = $_FILES['att']['name'];
$att_size = $_FILES['att']['size'];
$att_type = $_FILES['att']['type'];
#open, read then close the file
$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose( $fp );
#create a boundary string
$num = md5(time());
$str = "==Multipart_Boundary_x{$num}x";
#encode the data for safe transit
#and intersperse 76-character chunks with \r\n
$file = chunk_split(base64_encode($file));
#define header
$hdr = "www.deanross.com.au\n";
$hdr .= "MIME-Version: 1.0\n";
$hdr .= "Content-Type: multipart/mixed;\n ";
$hdr .= "boundary=\"{$str}\"";
#define message
$msg = "This is a multi-part message in MIME format\n\n";
$msg .= "--{$str}\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 16bit\n\n";
$msg .= "$message\n\n";
$msg .= "--{$str}\n";
#define the non-text attachment
$msg .= "Content-Type: {$att_type};\n";
$msg .= "name=\"{$att_name}\"\n";
$msg .= "Content-Disposition: attachment;\n";
$msg .= "filename=\"{$att_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= "$file\n\n";
$msg .= "--{$str}";
$ok = mail( $to, $subject, $msg, $hdr);
// if ($ok ==true){
// header('Location: sends.php');
// }else{
// header('Location: conactPage.php');
// }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
If(empty($errors)=== false){?>
<table class="errorT" ><tr >
<td><fieldset><legend>You are missing some fields</legend><div class="errorIndent"><ol class="errorRed">
<?php
foreach ($errors as $error){
echo "<li>", $error," <font >Please fix</font></li>";
}
?>
</ol>Click to Return to contacts page to fill in <font > required</font> missing fields:<INPUT TYPE="button" VALUE="Fix missing fields" onClick="history.go(-1);"> </div></fieldset></td>
</tr>
</table>
<?php
}else {
if(isset( $to, $subject,$msg, $hdr)) {
$ok;
}
}
?>
<form method="post" name="contactform" action="" enctype="multipart/form-data">
<input name="name" id="name" size="16" maxlength="16" placeholder="Type in first Name" /><br>
<input name="email" id="email" type="text" size="36" placeholder="Type in your Email Adderess"n/><br>
<textarea rows="5" cols="70" id="looking" name="looking" placeholder="test purpores"></textarea><br>
<label for='photo'> Have a nice photograph? I would love to see it</label><label for='photo' >:</label>
<input type="file" name="att" value=" "/><br>
<input type="submit" value="Send Email" name="submit" > <input type="reset" value="Reset Form"> <input name="send" type="hidden" value="true" />
</form>
</body>
</html>
if any one has or nows of a better and simple contact form with attachment who can help.