/*
Program : File Uploading and Mail Sending Process
*/
/*
1. Initially upload the file into "mail_upload" folder
2. So, we must changed the folder permission of "mail_upload" into 777 (write permission)
3. Sending mail with the File Attachment
Note : Change the Below listed variable values.. for your SETTINGS resp.
Line No: 31 ( $whereto )
Line No: 63 ( $mailto )
Line No: 64 ( $from_mail )
Line No: 65 ( $from_name )
Line No: 66 ( $replyto )
Line No: 67 ( $subject )
Line No: 68 ( $message )
*/
$error = ""; // Set a variable that will be used for errors
if(isset($_POST['upload']) && $_POST['upload'] == 'Send into Mail') // Form is submitted
{
$whereto = "/home2/nasc/dev/ingrams/mail_upload"; // Gets post value from select menu
$whatfile = $_FILES['uploadedfile']['name']; // Gets file value from file upload input
if(empty($whereto)) // Checks to see if $whereto is empty, if so echo error
$error = "You need to choose a directory.
";
if($whatfile == NULL) // Checks to see if file input field is empty, if so throw an error
$error .= "You need to choose a file.";
if(!empty($whereto) && $whatfile != NULL) //if no errors so far then continue uploading
{
$target_path = "$whereto/"; // The directory the file will be placed
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename($whatfile);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "
Uploaded Success : ".basename($whatfile);
$file_name = basename($whatfile);
$file_path = $whereto."/";
mail_attachment ($file_name, $file_path);
}
else /* if there was a problem then throw an error */
$error .= "There was an error uploading the file, please try again!";
}
}
function mail_attachment($filename, $path) {
global $error;
$mailto = "mano_ilayans@yahoo.com";
$from_mail = "manoilayans@gmail.com";
$from_name = "Manokaran";
$replyto = "manoilayans@gmail.com";
$subject = "File Uploading and Mailing Process";
$message = "Message of File Uploading and Mailing Process";
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "
2. Mail send ...
OK
"; // or use booleans here
} else {
$error .= "
Mail send ...
ERROR!";
}
}
?>
Subscribe to:
Post Comments (Atom)
Popular Posts
-
1. How old PHP language is? - PHP began in 1994, so 14 years old. 2. What are different names of PHP? - PHP originally stood for Persona...
-
HTML: a. HTML is a markup language that is used to build static (non interactive and nonanimated) webpages. b. HTML is Case-Insensitive. So...
-
A payment gateway is an e-commerce application service provider service that authorizes payments for e-businesses, online retailers, bricks...
-
Note : This is not a perfect sort order, we have just displaying the list of PHP companies. 1. Photon Infotech No. 2/102, Arvind IT Park (N...
-
- count() -- Count elements in a variable - syntax for count() [int count ( mixed var [, int mode])] - If the optional mode parameter is set...
-
Hai all, Simple show hide sample using Show/Hide? Simple Show/Hide code
-
Sharing PHP, MySQL, Javascript, CSS Knowledge, We can share our PHP knowledge on the basis of PHP versioning, Javascript, AJAX, Stylesheet, ...
-
Use the below code and you can get the exact value in php as us saw in browser. Code: $encode_data = iconv('UTF-8', 'windows-125...
-
Download and Enjoy!
-
A hyperlink is a text or a image that you can click on, and move from one page to another web page. Syntax: < a href= "web pag...
No comments:
Post a Comment