<?php
ini_set('error_reporting', E_NONE);
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
//Read POST request params into global vars
$to = "xyz@gmail.com";
$from = "info@rubiksol.in";
$subject = "New Resume";
$message_to_send = "Please find the attachment";
if (isset($_FILES["attachment_file"]) && $_FILES['attachment_file']['name'] != "")
{
// Obtain file upload vars
$attachment_file = $_FILES['attachment_file']['tmp_name'];
$attachment_file_type = $_FILES['attachment_file']['type'];
$attachment_file_name = $_FILES['attachment_file']['name'];
$name = $_FILES['attachment_file']['name'];
$size = $_FILES['attachment_file']['size'];
//Allowed file types - You may specify more if you wish
$allowedExtensions = array("jpg","jpeg", "gif","png","doc","docx","txt","rtf","pdf","zi p");
$attached_file_extension = pathinfo($name, PATHINFO_EXTENSION);
//$attached_file_extension = end(explode(".", $name)); You can still use this instead if you wish
function isAllowedExtension($attachmentFile)
{
global $allowedExtensions;
global $attached_file_extension;
return in_array($attached_file_extension, $allowedExtensions);
}
if (!isAllowedExtension($_FILES['attachment_file']['name']) )
{
echo '<br clear="all" /><div class="info" align="left">Sorry, you attached an invalid file type. <br>We only accept jpg, jpeg, gif, png, doc, docx, txt, rtf, pdf and zip files. Thanks.</div>';
}
else
{
if($size<(1024*1024))
{
$headers = "From: $from";
if (is_uploaded_file($attachment_file))
{
// Read the file to be attached ('rb' = read binary)
$file = fopen($attachment_file,'rb');
$data = fread($file,filesize($attachment_file));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message_to_send . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$attachment_file_type};\n" .
" name=\"{$attachment_file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$attachment_file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$vasplus_mailer_delivers_greatly = @mail($to, $subject, $message, $headers);
if ($vasplus_mailer_delivers_greatly)
{
echo '<font style="font-size:0px;">vpb_sent&</font>';
echo "<br clear='all' /><div align='left' class='info'>Done successfully! Thanks.</div>";
}
else
{
echo "<br clear='all' /><div align='left' class='info'>Sorry, your email could not be sent at the moment. Please try again or contact this website admin to report this error message if the problem persist (1). Thanks.</div>";
}
}
else
{
echo "<br clear='all' /><div class='info' align='left'>File exceeded 1MB max allowed file size. <br>Please upload a file at 1MB in size to proceed. Thanks.</div>";
}
}
}
//Else if the user did not attach a file above, then proceed with the email sending below - (we will send a HTML type of Email instead)
else
{
}
}
?>