WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Email attachment code
Categories : PHP, Email, Filesystem Click here to Update Your Picture
dheeraj dhawan
Date : May 02nd 2009
Grade : 5 of 5 (graded 2 times)
Viewed : 3641
File : 4962.php
Images : No Images for this code example.
Search : More code by dheeraj dhawan
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
// Path to the file
$fileatt = "";

// File Type
$fileatt_type = "application/octet-stream";

// Filename that will be used for the file as the attachment
$fileatt_name = "";

// Who the email is from
$email_from = "";

// The Subject of the email
$email_subject = "";

// Message that the email has in it
$email_txt = "";

// Who the email is too
$email_to = "";

$headers = "From: ".$email_from;

// check if your file is exist in your folder or not
if (file_exists($fileatt)) {
    echo
"The file $fileatt exists";
}else{
    echo
"The file $fileatt does not exist";
}


$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);


$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

$email_message .=    "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" .
                   
"Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if(
$ok) {
    echo
"<font face=verdana size=2>The file was successfully sent!</font>";
}else{
    die(
"Sorry but the email could not be sent. Please go back and try again!");
}
?>



PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
How to ifconfig down/up a list of IP's
Categories : Arrays, Strings, Filesystem, PHP
validateEmail 2.0 - upgraded version of the old validateEmail function used to validate email addresses via SMTP and regex.
Categories : Email, Regexps, PHP
Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
Solution to those 'tell-a-friend' type email issues
Categories : PHP, Email, Databases, MySQL
Working with files - putting file contents to a string / var
Categories : PHP, Filesystem, Variables, Strings
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
how can I read the entire contents of a file into a string?
Categories : Filesystem, Strings, PHP
filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory, filtered by regular expression and either sorted or randomized. Good for random pictures and graphics.
Categories : PHP, Filesystem, Directories
Single-file PHP news system with automatic folder structure creation
Categories : PHP, Filesystem, Arrays
Protect your email links from being spidered by spam email robots!
Categories : PHP, Security, Mail, Email
Quote For the Day
Categories : PHP, Utilities, Filesystem