<?php
if(isset($_POST['submit'])) {
//Deal with the email
$to = "engr.lukman@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = strip_tags($_POST['message']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From:" .$name." : ".$email;
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
if($name!="" && $subject!="" && $message!="") {
if($email!="") {
if(preg_match("/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})+$/",$email))
{
$output = '<h1 style=\"color:green\">'."Thank you ".$name.'</h1>';
mail($to, $subject, $message, $headers);
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Please enter a valid email !!</h1>";
}
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Email should not empty !!</h1>";
}
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Mail not send successfully !</h1>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mail File</title>
</head>
<body>
<?php echo $output; ?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<p> Name : <input type="text" name="name" /> * </p>
<p> Email : <input type="text" name="email" /> * </p>
<p> Subject <input type="text" name="subject" /> * </p>
<p> Message <textarea name="message" id="message" cols="20" rows="5"></textarea> </p>
<p><label for="file">Attach a File : </label> <input type="file" name="file" id="file"></p>
<p><input type="submit" name="submit" id="submit" value="Send"></p>
</form>
</body>
</html>
if(isset($_POST['submit'])) {
//Deal with the email
$to = "engr.lukman@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = strip_tags($_POST['message']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From:" .$name." : ".$email;
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
if($name!="" && $subject!="" && $message!="") {
if($email!="") {
if(preg_match("/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})+$/",$email))
{
$output = '<h1 style=\"color:green\">'."Thank you ".$name.'</h1>';
mail($to, $subject, $message, $headers);
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Please enter a valid email !!</h1>";
}
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Email should not empty !!</h1>";
}
}
else {
echo "<h1 align=\"center\" style=\"color:red\">Mail not send successfully !</h1>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mail File</title>
</head>
<body>
<?php echo $output; ?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<p> Name : <input type="text" name="name" /> * </p>
<p> Email : <input type="text" name="email" /> * </p>
<p> Subject <input type="text" name="subject" /> * </p>
<p> Message <textarea name="message" id="message" cols="20" rows="5"></textarea> </p>
<p><label for="file">Attach a File : </label> <input type="file" name="file" id="file"></p>
<p><input type="submit" name="submit" id="submit" value="Send"></p>
</form>
</body>
</html>