if($_POST['button'] && isset($_FILES['attachment']))
{
$from_email = 'sender@abc.com';
$recipient_email = 'recipient@xyz.com';
$sender_name = $_POST["sender_name"]
$reply_to_email = $_POST["sender_email"]
$subject = $_POST["subject"]
$message = $_POST["message"]
$tmp_name = $_FILES['my_file']['tmp_name'];
$name = $_FILES['my_file']['name'];
$size = $_FILES['my_file']['size'];
$type = $_FILES['my_file']['type'];
$error = $_FILES['my_file']['error'];
if($file_error > 0)
{
die('Upload error or No files uploaded');
}
$handle = fopen($tmp_name, "r");
$content = fread($handle, $size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("random");
$headers = "MIME-Version: 1.0
";
$headers .= "From:".$from_email."
";
$headers .= "Reply-To: ".$reply_to_email."
";
$headers .= "Content-Type: multipart/mixed;";
$headers .= "boundary = $boundary
";
$body = "--$boundary
";
$body .= "Content-Type: text/plain; charset=ISO-8859-1
";
$body .= "Content-Transfer-Encoding: base64
";
$body .= chunk_split(base64_encode($message));
$body .= "--$boundary
";
$body .="Content-Type: $type; name=".$name."
";
$body .="Content-Disposition: attachment; filename=".$name."
";
$body .="Content-Transfer-Encoding: base64
";
$body .="X-Attachment-Id: ".rand(1000, 99999)."
";
$body .= $encoded_content;
$sentMailResult = mail($recipient_email, $subject, $body, $headers);
if($sentMailResult )
{
echo "File Sent Successfully.";
unlink($name);
}
else
{
die("Sorry but the email could not be sent.
Please go back and try again!");
}
}