Ashish Sood Posted June 22, 2014 Share Posted June 22, 2014 Hi , I have created a php script which can send a attachment with mail but i want to give browse option to user so that they can choose the file which they want to send but i don't know to render this function with php email script I have created front end and sample email script. hope you understand my requirement . [Front end] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><title>Email testing </title></head><body><form method="post" action="back.php" enctype="multipart/form-data">Incoming :<input name="incoming" type="text" />Outgoing :<input name="outgoing" type="text" />Comments :<textarea name="comments" cols="20" rows="2"></textarea><input name="attachment" type="file" style="width: 216px; height: 26px" /><br /><br /><input name="submit" type="submit" value="Submit" /></form></body></html> My Sample email script which sends defined attachement. <html><head><title>Sending attachment using PHP</title></head><body><?php $to = "sample@abc.com"; $subject = "offer letter"; $message = "This is test message."; # Open a file $file = fopen( "upload/test.txt", "r" ); if( $file == false ) { echo "Error in opening file"; exit(); } # Read the file into a variable $size = filesize("upload/test.txt"); $content = fread( $file, $size); fclose($file); # encode the data for safe transit # and insert rn after every 76 chars. $encoded_content = chunk_split(base64_encode($content)); # Get a random 32 bit number using time() as seed. $num = md5( time() ); # Define the main headers. $header = "From:testing@sample.comrn"; $header .= "MIME-Version: 1.0rn"; $header .= "Content-Type: multipart/mixed; "; $header .= "boundary=$numrn"; $header .= "--$numrn"; # Define the message section $header .= "Content-Type: text/plainrn"; $header .= "Content-Transfer-Encoding:8bitrnn"; $header .= "$messagern"; $header .= "--$numrn"; # Define the attachment section $header .= "Content-Type: multipart/mixed; "; $header .= "name="test.txt"rn"; $header .= "Content-Transfer-Encoding:base64rn"; $header .= "Content-Disposition:attachment; "; $header .= "filename="test.txt"rnn"; $header .= "$encoded_contentrn"; $header .= "--$num--"; # Send email now $retval = mail ( $to, $subject, $message, $header ); if( $retval == true ) { echo "Messageaahh sent successfully..."; } else { echo "Message could not be sent..."; }?></body></html> Please reply me soon Thanks.... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2014 Share Posted June 23, 2014 Instead of getting the contents of a text file, you'll need to have PHP validate the uploaded file and get the data from that file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now