note 78208 added to ref.mail

From: Date: Wed, 03 Oct 2007 05:01:34 +0000
Subject: note 78208 added to ref.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-131024@lists.php.net to get a copy of this message
I am trying to send an e-mail with an attachment and I am clueless as to what might be the problem! I have the following code, that works to send the e-mail as well as show that there is an attachment, but the attachment is a blank file and not the one uploaded. How can I do this? Here's the code: <?php //define the receiver of the email $to = 'brottmayer@gmail.com'; //define the subject of the email $subject = Trim(stripslashes($_POST['subject']));; //define the sender of the email $from = Trim(stripslashes($_POST['from']));; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: $from\r\nReply-To: $from"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //Userfile information $filename = $_FILES["userfile"]["name"]; // gives you the name of the file they uploaded $filetype = $_FILES["userfile"]["type"]; // gives you the size of the upload in bytes $filetemp = $_FILES["userfile"]["tmp_name"]; // gives you the temporary name of the file on the server until it is renamed //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $data = base64_encode($filename); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. Address is: <?php echo $_POST["address"]; ?> Phone Number is: <?php echo $_POST["phone"]; ?> Birthdate is: <?php echo $_POST["bdate"]; ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> <h1>Address is: <?php echo $_POST["address"]; ?></h1> <p>Phone Number is: <?php echo $_POST["phone"]; ?><br /> Birthdate is: <?php echo $_POST["bdate"]; ?></p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: $filetype; name=$filename Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $data; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 189.146.203.180 ---- Manual Page -- http://www.php.net/manual/en/ref.mail.php Edit -- https://master.php.net/note/edit/78208 Del: integrated -- https://master.php.net/note/delete/78208/integrated Del: useless -- https://master.php.net/note/delete/78208/useless Del: bad code -- https://master.php.net/note/delete/78208/bad+code Del: spam -- https://master.php.net/note/delete/78208/spam Del: non-english -- https://master.php.net/note/delete/78208/non-english Del: in docs -- https://master.php.net/note/delete/78208/in+docs Del: other reasons-- https://master.php.net/note/delete/78208 Reject -- https://master.php.net/note/reject/78208 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131024) next »